Latex:列表中的中心文本

发布于 2024-08-30 12:12:02 字数 63 浏览 5 评论 0原文

如何在 Latex 中将文本置于列表中?

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

How do I center text within a listing in Latex?

Or another way not using listing. (Need a box with monospace font)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倦话 2024-09-06 12:12:02

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 位有什么作用?

The answer given at tex.stackexchange is:

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

...which still leaves me wondering:

Using a frame around the code, e.g. using \lstset{frame=single,frameround=tttt}, places the frame way over to the right. How can this be avoided?

What does the renewcommand bit do?

千寻… 2024-09-06 12:12:02

我对列表包没有答案,但您可以尝试以下操作:

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

I don't have an answer for the listing package on top of my head, but you could try the following:

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

That produces a box with 90% of the line width, with text of width 85% of line width.

If you want it centered you just put \centering in front of the \tt command:

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

If you prefer the box without a frame, simply change \framebox into \makebox (and keep the arguments as they stand).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文