[Tex/LaTex] Dynamic vspace depending on text height

spacing

I have a fixed layout with some text and vspace s and so on.
Sometimes one of the text passages is too long for one line, so it uses two or more lines.

Is there any possibility to get the used height of the text and adjust the vspace?

Here is a little part out of my sty file:

\begin{center}
    {\Large\thethema}\\
    \vspace{1.6cm}
\end{center}

For one line 1.6 cm is good, but for two lines it is too much and the title page needs two pages.

Thanks for any hints.

Best Answer

Normally you should be able to define stretchable "rubber" glue that automatically adjusts to the available space however if you really need to take different action depending on the number of lines you can do that as follows:

\documentclass{article}

\begin{document}



\begin{center}
    \Large aaa

   \ifnum\prevgraf=1
    \vspace{1.6cm}
   \else
    \vspace{1cm}
  \fi
\end{center}



\begin{center}
    \Large \def\a{aaa aa aa aa a}\a\a\a\a\a

   \ifnum\prevgraf=1
    \vspace{1.6cm}
   \else
    \vspace{1cm}
  \fi
\end{center}

\end{document}

Note the blank line (or an equivalent command) before the test is needed so the paragraph is completed and \prevgraf updated with the number of lines in the previous paragraph.

Related Question