5

I thought I'd wrap up the evening by quickly vertically centering some text in LaTeX. But, of course, that's not how LaTeX works :/.

I've taken this simple approach.

Here's my MWE:

\documentclass{article}
\begin{document}
\thispagestyle{empty}
\setlength{\parindent}{0cm} % this kills the indentation
\Huge
\vspace*{\fill}
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
\vspace*{\fill}
\end{document}

This does not yield precisely vertically centered text, and I have no idea why.

enter image description here

I'm probably missing something obvious.


Update 1: I tried the fix commented by @GuM but it doesn't seem to help.

\documentclass{article}
\begin{document}
\thispagestyle{empty}
\setlength{\parindent}{0cm} % this kills the indentation
\Huge
\vspace*{-1\topskip plus 1fill}
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
\par
\vspace*{\fill}
\end{document}

enter image description here

maxheld
  • 287
  • 2
    Try replacing \vspace*{\fill} with \vspace*{-1\topskip plus 1fill} (note the 1 before \topskip!). I’d also add \par before the second \vspace. – GuM Jul 08 '17 at 21:55
  • Related to / possible duplicate of: Why does \vspace*{0pt} add vertical space?. – GuM Jul 08 '17 at 22:02
  • @GuM thanks; I tried \vspace*{-1\topskip plus 1fill} but to no avail (see above update). – maxheld Jul 10 '17 at 18:30
  • @GuM not sure this is the same issue as you mention; I tried \topskip=0pt but it also did not resolve the problem. – maxheld Jul 10 '17 at 18:31
  • In your picture you show two red boxes: how are they positioned on the page, exactly? I mean, where does the upper edge (resp., the lower edge) of the first (resp., the second) box lie? – GuM Jul 18 '17 at 23:37
  • sorry; upper and lower edge of the red boxes lie at the physical paper margins. I added them post-compilation with Preview. They here merely serve to illustrate that the text is not, in fact, vertically centered. – maxheld Jul 19 '17 at 07:21
  • be aware that the text area and the page area are two different things. \voffset+\headsep+\headheight+\topmargin make the upper margin between paper and text body; \paperheight-(\voffset+\headsep+\headheight+\topmargin+\textheight) make up the bottom margin. You need to include this into your calculations before you vertically align the motto. – Lupino Dec 20 '17 at 13:30

1 Answers1

3

In addition to the \vspace*{-1\topskip plus 1fill} suggested by GuM, I placed the typeset content in a \vbox. Note the the content is centered assuming the bottom of the \vbox is the baseline of the bottom line of text.

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\begin{document}
\thispagestyle{empty}
\setlength{\parindent}{0cm} % this kills the indentation
\Huge
\vspace*{-1\topskip plus 1fill}
\vbox{
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.}
\vspace*{\fill}
\end{document}

enter image description here

To get the centering to account for descenders on the bottom line of text, I used a minipage instead of a \vbox, and enclosed the minipage inside of an \fbox:

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\begin{document}
\thispagestyle{empty}
\setlength{\parindent}{0cm} % this kills the indentation
\Huge
\vspace*{-1\topskip plus 1fill}
\fboxrule=0pt\relax
\fboxsep=-\fboxrule\relax
\fbox{\begin{minipage}{\textwidth}
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
Arbeiten von zu Hause erlaubt es mir, Job und Familie problemlos zu vereinbaren.
\end{minipage}}
\vspace*{\fill}
\end{document}

enter image description here