给定一些文本,我想在给定数量的行上集中对齐该文本。
例如,
\documentclass{article}
\begin{document}
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna.
\end{document}
给出 然而,我建议 LaTeX 将此文本分布在 12 行中,其中所有行(包括最后一行)的宽度大致相同。此外,输出应居中。
答案1
\documentclass{article}
\usepackage[latin]{babel}
\begin{document}
\sbox0{\indent Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna.}
\begin{center}
\dimen0=\dimexpr\wd0/12\relax
\loop
\sbox2{\parbox[b]{\dimen0}{\parfillskip=0pt plus .1\hsize\unhcopy0}}
\ifdim\ht2>12\baselineskip
\advance\dimen0 1em
\repeat
\usebox2
\end{center}
\end{document}
如果你改为
\documentclass{article}
\usepackage[latin]{babel}
\begin{document}
\sbox0{Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna.}
\begin{center}
\dimen0=\dimexpr\wd0/12\relax
\loop
\sbox2{\parbox[b]{\dimen0}{\centering\parfillskip=0pt \unhcopy0}}
\ifdim\ht2>12\baselineskip
\advance\dimen0 .5em
\repeat
\usebox2
\end{center}
\end{document}
然后你得到