2

如何在 Latex 列表中居中文本?

或者另一种不使用列表的方式。(需要一个等宽字体的盒子)

4

2 回答 2

2

tex.stackexchange给出的答案是:

\documentclass{article}
\usepackage{listings}
\renewcommand{\figurename}{Listing}
                    % replace figurename with the text that should preceed the caption
\begin{document}

\begin{figure}[thp] % the figure provides the caption
\centering          % which should be centered
\caption{Ausgabe des C-Programms}
\begin{tabular}{c}  % the tabular makes the listing as small as possible and centers it
\begin{lstlisting}[label={gtt_c_ausgabe}]
printf("Your code goes here.\n");
\end{lstlisting}
\end{tabular}
\end{figure}

\end{document}

...这仍然让我想知道:

在代码周围使用框架,例如 using \lstset{frame=single,frameround=tttt},将框架放置在右侧。如何避免这种情况?

比特有什么作用renewcommand

于 2011-03-24T15:31:26.573 回答
0

对于头顶上的列表包,我没有答案,但您可以尝试以下方法:

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\tt Hello World\\Second line}}

这会产生一个线宽为 90% 的框,文本宽度为线宽的 85%。

如果你想让它居中,你只需放在命令\centering前面\tt

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\centering \tt Hello World\\Second line}}

如果您更喜欢没有框架的盒子,只需更改\framebox\makebox(并保持参数不变)。

于 2010-04-27T06:45:39.233 回答