# line break so both lines have same width

I have a long string of text and it takes up more than one line. I want the line break to happen so that the first line and the second line have the same width. How do I do this?

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


into this (kind of)

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


This is a very simple-minded proposal: measure the width of the text and put it in a minipage of half this width.

\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}


A slightly more sophisticated solution: loop till the text is just wide enough to fit into two lines.

\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
\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}


• I like the second way. It almost did what I want, but it chose the width slightly too short so that the last word got hyphenated onto a 3rd line. Mar 27, 2020 at 3:58
• @R.B.Jawad But the output is shown and only has two lines. I do not understand this comment.
– user194703
Mar 27, 2020 at 3:59
• The variation seems to work. Here is the text that failed with the first way: \BreakEven{\textit{\footnotesize Sundays in Advent at Prime, and on the day of Saint Paul the apostle}} Mar 27, 2020 at 4:08
• Is there a way to do it so that the spacing is not messed up between words? The right end can be ragged. Mar 27, 2020 at 4:13
• @R.B.Jawad I didn't expect you to change the font size inside the macro. I updated the answer accordingly. This fixes the spacing, too.
– user194703
Mar 27, 2020 at 4:15