Latex:在列表中居中显示文本

Latex:在列表中居中显示文本,latex,listings,Latex,Listings,如何在Latex中使列表中的文本居中 或者另一种不使用列表的方式。(需要一个带有monospace字体的框)我头上没有列表包的答案,但您可以尝试以下方法: \framebox[.9\linewidth]{\parbox{.85\linewidth}{\tt Hello World\\Second line}} 这将生成一个具有90%线宽的框,文本的宽度为85%线宽 如果要使其居中,只需将\centering放在\tt命令前面: \framebox[.9\linewidth]{\parbox{.

如何在Latex中使列表中的文本居中


或者另一种不使用列表的方式。(需要一个带有monospace字体的框)

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

\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
(并保持参数不变)。

给出的答案是:

…这仍然让我疑惑:

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

renewcommand
位的作用是什么

\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}