8

I am testing a new layout for my invoice. I am trying to put some small vertical spacing before the invoice title. While tesing the vertical spacing, I have spotted a strange behaviour, and reduced it to 0 just to see what happens:

\begin{document}

\vspace*{0 mm}

{\LARGE\center <<title>>\\}

\vspace{10 mm}

...

And this produces a different layout than:

\begin{document}

{\LARGE\center <<title>>\\}

\vspace{10 mm}

...

In the first case, there is substantial vertical space (even though I am setting i to 0 mm), and in the second one there is none. Why?

blueFast
  • 201
  • 9
    Your are (wrongly) using the command \center which actually starts the center environment, which is a list. \vspace*{} puts an invisible box on the page and so the space before this list is no longer discarded at the start of a page. Better use {\LARGE\centering Title \par}. – Ulrike Fischer Jan 31 '14 at 12:23

1 Answers1

12

The following examples are using \centering instead of environment center, see question "When should we use \begin{center} instead of \centering?" for details.

\showlists can be used to analyze the spacing:

% configuring, how much is shown by `\showlists` or `\showbox`
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen

\documentclass{article}

\begin{document}

  \vspace*{0mm}

  {\LARGE\centering Title}

  \showlists
\end{document}

Result:

### vertical mode entered at line 0
### current page:
\write-{}
\glue(\topskip) 10.0
\rule(0.0+0.0)x*
\penalty 10000
\glue 0.0
\glue 0.0
\glue(\parskip) 0.0 plus 1.0
\glue(\baselineskip) 0.0
\hbox(12.0+0.0)x345.0, glue set 311.69482fil
.\hbox(0.0+0.0)x0.0
.\OT1/cmr/m/n/17.28 T
.\OT1/cmr/m/n/17.28 i
.\OT1/cmr/m/n/17.28 t
.\OT1/cmr/m/n/17.28 l
.\OT1/cmr/m/n/17.28 e
.\penalty 10000
.\glue(\parfillskip) 0.0 plus 1.0fil
.\glue(\rightskip) 0.0
total height 22.0 plus 1.0
 goal height 550.0
prevdepth 0.0, prevgraf 1 line

Thus the page contains as additional white space elements before the title:

  • \topskip, it is a parameter that helps to align the first lines on the pages. It is only automatically added at the top of the page. On this page, however, there is not a "first line" to align. Thus it can be set to zero.

  • \parskip, here 0pt plus 1pt, but it might be different.

  • \baselineskip, here 0pt, because the next line is over large (\LARGE).

The following example avoids these white spaces:

\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen

\documentclass{article}

\begin{document}

  \begingroup
    \setlength{\topskip}{0mm}% \topskip is set to zero
    \vspace*{0mm}%
    \setlength{\parskip}{0pt}% \parskip is set to zero
    \nointerlineskip % avoids addition of \baselineskip before next line
    \centering
    \LARGE
    Title
    \par
  \endgroup

  \showlists

\end{document}

Result:

### vertical mode entered at line 0
### current page:
\write-{}
\glue(\topskip) 0.0
\rule(0.0+0.0)x*
\penalty 10000
\glue 0.0
\glue 0.0
\glue(\parskip) 0.0
\hbox(12.0+0.0)x345.0, glue set 155.84741fil
.\glue(\leftskip) 0.0 plus 1.0fil
.\hbox(0.0+0.0)x0.0
.\OT1/cmr/m/n/17.28 T
.\OT1/cmr/m/n/17.28 i
.\OT1/cmr/m/n/17.28 t
.\OT1/cmr/m/n/17.28 l
.\OT1/cmr/m/n/17.28 e
.\penalty 10000
.\glue(\parfillskip) 0.0
.\glue(\rightskip) 0.0 plus 1.0fil
total height 12.0
 goal height 550.0
prevdepth 0.0, prevgraf 1 line

Thus the title hits the top of the text area. It can be visualized by option showframe of package geometry:

\documentclass[a5paper]{article}
\usepackage[
  showframe,
  % smaller image for answer in TeX.SX
  paperwidth=5cm,
  paperheight=5cm,
  margin=5mm,
  includeheadfoot,
]{geometry}

\begin{document}

  \begingroup
    \setlength{\topskip}{0mm}%
    \vspace*{0mm}%
    \nointerlineskip
    \setlength{\parskip}{0pt}%
    \centering
    \LARGE
    Title
    \par
  \endgroup

\end{document}

Result

Heiko Oberdiek
  • 271,626