如何在Latex的列表中居中文本?
或者不使用商品信息的其他方式。 (需要一个等宽字体的盒子)
答案 0 :(得分:1)
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}
......这仍让我感到疑惑:
在代码周围使用框架,例如使用\lstset{frame=single,frameround=tttt}
,将框架放置在右侧。如何避免这种情况?
renewcommand
位做什么?
答案 1 :(得分: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
(并保持参数不变)。