
長いテキスト文字列があり、それが 1 行以上を占めています。最初の行と 2 番目の行の幅が同じになるように改行したいのですが、どうすればよいですか?
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}
もう少し洗練された解決策: テキストが 2 行に収まるだけの幅になるまでループします。
\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}