1

How can I set a paragraph to a certain absolute number of lines?

Desired outcome

Case 1: Text length is shorter

Remaining space should be filled with blank lines

Case 2: Text length is dead on

Nothing to do

Case 3: Text length is longer

Following paragraph should start position at as if the text had exactly the specified length

Example

\documentclass{article}

\begin{document}
Let's say the text should be 5 lines long

\section{Short}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\vspace{2\baselineskip}

Following paragraph

\section{Long}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\vspace{-1\baselineskip}

Following paragraph
\end{document}

EDIT: Or even better, throw an error if text is too long

1

You can measure the paragraph's length. Some adjustments for keeping the current status of \if@nobreak and \everypar is necessary.

\documentclass{article}
\usepackage{environ}

\makeatletter
\NewEnviron{parlines}[1]{%
  \par
  \if@nobreak\def\kept@nobreak{\@nobreaktrue}\else\def\kept@nobreak{}\fi
  \edef\kept@everypar{\the\everypar}%
  \setbox0=\vbox{\BODY\@@par\xdef\parlinesprevgraf{\the\prevgraf}}%
  \kept@nobreak
  \everypar=\expandafter{\kept@everypar}%
  \ifnum\parlinesprevgraf>#1\relax
    ERROR, too long,\par\vspace{#1\baselineskip}%
  \else
    \BODY\par
    \vspace{\numexpr#1-\parlinesprevgraf\relax\baselineskip}%
  \fi
}
\makeatother

\begin{document}
Let's say the text should be 5 lines long

\section{Short}
\begin{parlines}{5}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\end{parlines}

Following paragraph

\section{Long}
\begin{parlines}{5}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\end{parlines}

Following paragraph
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.