我都快疯了。
我想在LaTeX中居中列出最后一个列表。
在尝试了3个小时之后,下面是一些代码:
\lstset{ %
caption=Descriptive Caption Text,
label=lst:descr_capti_text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb,
linewidth=0.6\textwidth
}
\centering\begin{tabular}{c}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{tabular}
这是把最后一个列表放在中间,而不是它的标题,也就是右边。如果我去掉表格,那么标题会居中,但代码会转到左边!:(
谢谢。
发布于 2010-06-24 08:51:42
您的标题实际上位于列表的中心。您只是将沿着列表顶部和底部的行设置为仅0.6\textwidth
长。这使得标题看起来像是偏离了中心。此外,您的\centering
不会使列表居中(如果不缩短下面和上面的行,则可见)。
这应该是可行的:
\begin{center}
\lstset{%
caption=Descriptive Caption Text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb
}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{center}
您不需要解释为什么希望定界行是0.6\textwidth
long。如果您实际上想要将列表的宽度设置为该值,那么您的方法并不能实现您想要的效果。使用像minipage这样的东西来设置整个列表的宽度。
begin{minipage}{0.6\textwidth}
\begin{center}
\lstset{%
caption=Descriptive Caption Text,
basicstyle=\ttfamily\footnotesize\bfseries,
frame=tb,
}
\begin{lstlisting}
printf("this should be centered!");
\end{lstlisting}
\end{center}
\end{minipage}
发布于 2011-01-22 23:33:20
实际上,对我来说起作用的是相反的情况:将微型机放在中心环境中。
https://stackoverflow.com/questions/3106419
复制相似问题