换行使两行具有相同的宽度

换行使两行具有相同的宽度

我有一串很长的文本,占了不止一行。我希望换行时第一行和第二行的宽度相同。我该怎么做?

A very long line of text that wraps around to the other line and needs to be broken differently.

变成这样

A very long line of text that wraps around to the 
other line  and needs  to be  broken  differently.

答案1

这是一个非常简单的建议:测量文本的宽度,然后将其放在宽度为该宽度一半的小页面中。

\documentclass{article} 
\newcommand\BreakEven[1]{\setbox0\hbox{#1}%
\begin{minipage}{\dimexpr0.5\wd0}
#1
\end{minipage}}
\begin{document}
\BreakEven{A very long line of text that wraps around to the other line and
needs to be broken differently.}
\end{document}

在此处输入图片描述

一个稍微复杂的解决方案:循环直到文本的宽度刚好适合两行。

\documentclass{article} 
\newlength\TestWidth
\newlength\MyBaseLineskip
\newcommand\BreakEven[2][1.5]{\setbox0\hbox{#2\global\MyBaseLineskip=\baselineskip}%
\TestWidth=0.45\wd0\relax
\loop
\setbox0\hbox{\begin{minipage}{\TestWidth}
#2
\end{minipage}}
\ifdim\ht0>#1\MyBaseLineskip\relax
\advance\TestWidth by 1pt\relax
\repeat
\begin{minipage}{\TestWidth}
#2
\end{minipage}}
\begin{document}
\BreakEven{A very long line of text that wraps around to the other line and
needs to be broken differently.}

\BreakEven{\footnotesize\textit{Sundays in Advent at Prime, and on the day of Saint Paul the apostle}}
\end{document}

在此处输入图片描述

相关内容