我有一些文本(如标题),需要居中,并且有一些注释(多行 - 注释 1 \\注释 2),这些注释应该位于其正下方和左侧:
Some centered text
note1
note2
我该怎么做?
答案1
使用varwidth
包裹:
\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\begin{document}
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
\begin{center}
\begin{varwidth}{\textwidth}
Here is some title that is somewhat long. \par
And some notes. \\
And some more notes.
\end{varwidth}
\end{center}
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text.
\end{document}
\textwidth
环境的宽度varwidth
确保文本适合文本块,但也会缩小到框的自然宽度(以防它不那么宽)。
为了保持标题居中(如果注释超出标题的宽度),您可以使用
\begin{center}
\begin{varwidth}{\textwidth}
\centerline{Here is some title that is somewhat long.} \par
And some notes. \\
And some more notes. And some more notes. And some more notes.
\end{varwidth}
\end{center}
但是,您需要\par
在此处使用标题。还有其他方法可以做到这一点。
这showframe
包裹仅仅强调了“中心性”。
答案2
您可以使用minipage
或varwidth
环境来表示文本。然后将整个内容放入center
环境中。
\documentclass{article}
\usepackage{varwidth}
\usepackage{lipsum}
\begin{document}
\lipsum[1]% dummy text
\begin{center}
\begin{varwidth}{5cm}
\textbf{Some title}\\
Node 1\\
Node 2
\end{varwidth}
\end{center}
\lipsum[2]% dummy text
\end{document}
当然,您可以使用adjustbox
它来简化代码。但env
不幸的是,当前版本中的密钥已损坏。我很快就会将修复程序上传到 CTAN。
\documentclass{article}
\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}
\lipsum[1]% dummy text
% Add `varwidth` and `center` environment (but broken in current version :-( )
\noindent\adjustbox{varwidth=5cm,env=center}{%
\textbf{Some title}\\
Node 1\\
Node 2
}
\lipsum[2]% dummy text
\noindent\adjustbox{varwidth=5cm,center,margin=0pt \bigskipamount}{% (`margin` adds a vertical skip above and belo)
\textbf{Some title}\\
Node 1\\
Node 2
}
\lipsum[3]% dummy text
\end{document}
答案3
如果行不需要换行,那么有一种无需额外包的简单方法:
\begin{center}
\begin{tabular}{@{}l@{}}
Some centered text\\
note1\\
note2
\end{tabular}
\end{center}