換行,使兩條線具有相同的寬度

換行,使兩條線具有相同的寬度

我有一長串文本,它佔用了不只一行。我希望發生換行,以便第一行和第二行具有相同的寬度。我該怎麼做呢?

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}

在此輸入影像描述

相關內容