中心乳胶列表
这让我发疯。
我想在 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}
这将 lstlisting 放在中心,但不将其标题放在右侧。如果我取出表格,则标题会居中,但代码会移至左侧! :(
谢谢。
This is driving me crazy.
I want to center a lstlisting in LaTeX.
After 3 hours attempting here's some code:
\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}
This is putting the lstlisting on the center but not its caption, that goes to the right. If I take out the tabular, then caption gets centered but the code goes to the left! :(
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该考虑使用xleftmargin和xrightmargin而不是使用线宽(参见
texdoc清单
,第4.10章)。以下代码无需任何中心或小型页面环境即可运行:Instead of using linewidth you should consider to use xleftmargin and xrightmargin (cf.
texdoc listings
, Chapter 4.10). The following code works without any center or minipage environment:您的标题实际上位于列表的中心。您只需将列表顶部和底部的线条设置为仅
0.6\textwidth
长。这使得标题看起来好像偏离中心。另外,您的\centering
不会使列表居中(如果您不缩短下面和上面的行,则可见)。这应该有效:
您没有解释为什么您希望分隔线的长度为
0.6\textwidth
。如果您实际上想将列表的宽度设置为该值,您的
方法并不能达到你想要的效果。使用类似迷你页的东西来设置宽度
对于整个列表。
Your caption is actually centered over the listing. You are just making the lines that run along the top and bottom of your listing only
0.6\textwidth
long. This makes it appear as if the caption was off-center. Also, your\centering
doesn't center the listing (visible if you don't shorten the lines below and above).This should work:
You don't explain why you want the delimiting lines to be
0.6\textwidth
long. Ifyou actually wanted to set the width of your listing to be that value, your
approach doesn't do what you want. Use something like a minipage to set a width
for the whole listing.
实际上,对我有用的是相反的:将小型页面放在中心环境中。
Actually, what did work for me is the converse: putting the minipage inside the center environment.