Why does a parbox of height zero consume vertical space?
First it is worth noting that \vspace
makes glue not a box, the other half of TeX's box and glue model for text layout.
If I modify your example to
\documentclass[11pt]{article}
\usepackage{blindtext}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\blindtext
\vspace{1cm}
%\parbox[c][0pt]{\linewidth}{} % When we add this line, the space between both paragraphs increases
X
%.
\vspace{1cm}
\blindtext
\end{document}
Then it is easier to see what is going on. you have three paragraphs of text two with lipsum, and one with X. The height of a text line does not (normally) depend on the specific characters in the line, if you replace X
by .
the character is smaller but the middle paragraph takes the same space. The \parbox
acts like a zero sized white character so is placed in a one-line paragraph and takes up the same vertical space as any other one line paragraph.
It may be worth noting that the parbox is not \linwidth
wide it is of zero width. If you placed any content inside the \parbox
such as
\parbox[c][0pt]{\linewidth}{.} %
then you will get an overfull hbox warning as you have a box of width \linewidth
indented by \parindent
(17pt).
Let's minimize the example
\documentclass{article}
\pagestyle{empty}
\showoutput
\begin{document}
Test
\vspace{30pt}% so we can see it better in the output
\parbox[c][0pt]{\linewidth}{}
\vspace{30pt}
Test
\end{document}
In the console output we see
Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0, glue set 455.9513fil
...\write-{}
...\glue(\topskip) 3.16669
...\hbox(6.83331+0.0)x345.0, glue set 311.33333fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 T
....\kern-0.83334
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 s
....\OT1/cmr/m/n/10 t
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 30.0
...\glue 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 9.5
...\hbox(2.5+0.0)x345.0, glue set 330.0fil
....\hbox(0.0+0.0)x15.0
....\mathon
....\vbox(2.5+-2.5)x0.0
.....\glue 0.0 plus 1.0fil minus 1.0fil
.....\glue 0.0 plus 1.0fil minus 1.0fil
....\mathoff
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 30.0
...\glue 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 5.16669
...\hbox(6.83331+0.0)x345.0, glue set 311.33333fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 T
....\kern-0.83334
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 s
....\OT1/cmr/m/n/10 t
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 0.0 plus 1.0fil
...\glue 0.0
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 30.0
..\hbox(0.0+0.0)x345.0
The \parbox
corresponds to
....\hbox(0.0+0.0)x15.0 % <- indent
....\mathon % <- start math mode
....\vbox(2.5+-2.5)x0.0 % <- a \vbox from \vcenter
.....\glue 0.0 plus 1.0fil minus 1.0fil % <- the glue for vertical centering
.....\glue 0.0 plus 1.0fil minus 1.0fil % <- the glue for vertical centering
....\mathoff
because the [c]
option uses internally math mode to do \vcenter
and the actual height and depth are 2.5pt (because of the standard height of the formula axis). However, the explanation lies just before this part, namely
....\glue(\parfillskip) 0.0 plus 1.0fil % <- the paragraph for Test has ended
....\glue(\rightskip) 0.0 % <- no \rightskip
...\glue 30.0 % <- the \vspace{30pt}
...\glue 0.0 % <- from \vspace implementation
...\glue(\parskip) 0.0 plus 1.0 % <- a paragraph has started
...\glue(\baselineskip) 9.5 % <- vertical glue
...\hbox(2.5+0.0)x345.0, glue set 330.0fil % <- a line
The final \hbox
is what encloses the \parbox
and is preceded by glue from \baselineskip
in the amount of 9.5pt: indeed, the height of the box is 2.5pt and 9.5 + 2.5 = 12 (the value of \baselineskip
).
Similarly, you see after the box
....\penalty 10000 % <- from \par
....\glue(\parfillskip) 0.0 plus 1.0fil % <- a paragraph has ended
....\glue(\rightskip) 0.0 % <- no \rightskip
...\glue 30.0 % <- \vspace{30pt}
...\glue 0.0 % <- from \vspace
...\glue(\parskip) 0.0 plus 1.0 % <- a paragraph has started
...\glue(\baselineskip) 5.16669 % <- glue
...\hbox(6.83331+0.0)x345.0, glue set 311.33333fil % <- the paragraph for Test
The \penalty 10000
is due to the blank line after \parbox
, which ends the paragraph.
If you do \parbox[c][0pt]{\linewidth}{X}
, then you'd see more: an Overfull \hbox
message, due to the indentation being followed by a box that make more the line width. However the vertical spacing between the two instances of “Test” would not change, because the parbox fits vertically in the \baselineskip
.
In other words, you have three paragraphs, with added vertical space between them.
Actually, the \vspace
commands are a kind of red herring. If you consider
\documentclass{article}
\pagestyle{empty}
\begin{document}
Test 1
Test 2
\parbox[c][0pt]{\linewidth}{}
Test 3
\end{document}
you get
It would be different if you used \nointerlineskip\vbox to 0pt{}
: here's a side by side comparison:
\documentclass{article}
\begin{document}
\settowidth{\dimen0}{Test 1}
\parbox{\dimen0}{Test 1
Test 2
Test 3}%
\parbox{\dimen0}{Test 1
Test 2
\nointerlineskip\vbox to 0pt{}
Test 3}
\end{document}