Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
you probably should have a look at tex.stackexchange.com/questions/476/…. You'll see that the defined vertical skip commands contain the dynamical plus and minus requested lengths. –  pluton Jul 23 '12 at 14:39
1  
Also never use a size changing command like \Large with {\Large....} without including the paragraph break (or for centering \\ in the scope of the size change otherwise you get large text onnormal baseline and so inconsistent line spacing –  David Carlisle Jul 23 '12 at 15:23
add comment

1 Answer

up vote 2 down vote accepted

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 \prevdepth updated with the number of lines in the previous paragraph.

share|improve this answer
    
I don't understand, what you mean with stretchable "rubber" glue. –  CSchulz Jul 23 '12 at 15:55
    
if you go \vspace{1cm minus 0.5cm plus 1cm} the space will try to be 1cm but if the text is going in to a minipage with fixed vertical size (or the actual page to \textheight then TeX will shrink it as low as 0.5cm or stretch it as large as 2cm. So given such a setting if the text takes more space the whitespace will shrink to accommodate it. –  David Carlisle Jul 23 '12 at 16:00
    
Sorry, but I don't know how to get it working. I have tried it, but it doesn't work. Furthermore I don't understand your hint with the minipage. –  CSchulz Jul 24 '12 at 7:21
    
well my answer here answers your specific question on detecting the number of lines in a previous paragraph. It's better for the site if you ask a different question if you want to ask about glue stretching. Please if you ask a new question always add a complete small document that shows the problem, not just tex fragment that can't be run on its own. –  David Carlisle Jul 24 '12 at 9:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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