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

  • 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 8 '17 at 21:55
  • Related to / possible duplicate of: Why does \vspace*{0pt} add vertical space?. – GuM Jul 8 '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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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