![字符(单词)下的水平对齐](https://linux22.com/image/422986/%E5%AD%97%E7%AC%A6%EF%BC%88%E5%8D%95%E8%AF%8D%EF%BC%89%E4%B8%8B%E7%9A%84%E6%B0%B4%E5%B9%B3%E5%AF%B9%E9%BD%90.png)
我正在尝试按以下方式对齐一些文本(如下所示,来自文字处理器):
最好的方法是什么?我应该使用makebox
es 吗?
以下是 MWE:
\documentclass{article}
\begin{document}
\begin{itemize}
\item{In outer space,\\
the change in pressure is dominated by unicorns at low temperature;\\
by gnomes at moderate temperature; and\\
by dwarves at high temperature.}
\item{Underwater,\\
the change in pressure is dominated by lemmings at low temperature;\\
by elves at moderate temperature; and\\
by trolls at high temperature.}
\end{itemize}
\end{document}
答案1
\phantom
例如,你可以使用如下方法:
\documentclass{article}
\usepackage{geometry}
\newcommand{\myplaceholder}{\phantom{the change in pressure is dominated }}
\begin{document}
\begin{itemize}
\item{In outer space,\\
the change in pressure is dominated by unicorns at low temperature;\\
\myplaceholder by gnomes at moderate temperature; and\\
\myplaceholder by dwarves at high temperature.}
\item{Underwater,\\
the change in pressure is dominated by lemmings at low temperature;\\
\myplaceholder by elves at moderate temperature; and\\
\myplaceholder by trolls at high temperature.}
\end{itemize}
\end{document}
\widthof
以下是使用该calc
包与以下包结合使用的替代版本\hspace
:
\documentclass{article}
\usepackage{geometry}
\usepackage{calc}
\newlength{\mylength}
\setlength{\mylength}{\widthof{the change in pressure is dominated}}
\begin{document}
\begin{itemize}
\item{In outer space,\\
the change in pressure is dominated by unicorns at low temperature;
\hspace{\mylength} by gnomes at moderate temperature; and
\hspace{\mylength} by dwarves at high temperature.}
\item{Underwater,\\
the change in pressure is dominated by lemmings at low temperature;
\hspace{\mylength} by elves at moderate temperature; and
\hspace{\mylength} by trolls at high temperature.}
\end{itemize}
\end{document}
答案2
通过使用tabular
:
\documentclass{article}
\begin{document}
\begin{itemize}
\item In outer space,\\
the change in pressure is dominated
\begin{tabular}[t]{@{} l}
by unicorns at low temperature;\\
by gnomes at moderate temperature; and\\
by dwarves at high temperature.
\end{tabular}
\item In outer space,\\
the change in pressure is dominated
\begin{tabular}[t]{@{} l}
by unicorns at low temperature;\\
by gnomes at moderate temperature; and\\
by dwarves at high temperature.
\end{tabular}
\end{itemize}
\end{document}
答案3
带有\Longunderstack
。
\documentclass{article}
\usepackage{stackengine}
\setstackEOL{\\}
\begin{document}
\begin{itemize}
\item In outer space,\\
the change in pressure is dominated \Longunderstack[l]{%
by unicorns at low temperature;\\
by gnomes at moderate temperature; and\\
by dwarves at high temperature.}
\item Underwater,\\
the change in pressure is dominated \Longunderstack[l]{%
by lemmings at low temperature;\\
by elves at moderate temperature; and\\
by trolls at high temperature.}
\end{itemize}
\end{document}
答案4
此解决方案使用\parbox
。请注意,页面上确实没有足够的空间容纳“and”。
\documentclass{article}
\usepackage{showframe}
\begin{document}
\begin{itemize}
\sbox0{the change in pressure is dominated }% measure width
\item In outer space,\\
\usebox0\parbox[t]{\dimexpr \linewidth-\wd0}{% remaining space
by unicorns at low temperature;\\
by gnomes at moderate temperature; and\\
by dwarves at high temperature.}
\item Underwater,\\
\usebox0\parbox[t]{\dimexpr \linewidth-\wd0}{%
by lemmings at low temperature;\\
by elves at moderate temperature; and\\
by trolls at high temperature.}
\end{itemize}
\end{document}