2

I have a document with this preamble:

\documentclass[12pt, b5paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% ...
\usepackage{geometry}
\geometry{
    vcentering=True,
    margin=2cm,
    showframe % show how the type block is set on the page
}
% ...
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}
\chead{top} % header
\rhead{}

The text in "top" is not vertically centred. How would I vertically centre it in the 2 cm margin (preferably without calculating the appropriate centring point)?

enter image description here

EDIT: Looking at the docs, I don't think vcentering does what I thought it does. Regardless, is there a way to vertically centre the header?

  • 1
    Welcome to TeX.SE. – Mico Sep 14 at 5:23
  • You wrote, "I don't think vcentering does what I thought it does." Not knowing what it is that you thought, let me quote from the package's user guide: "vcentering=true sets auto-centering vertically and is equivalent to vmarginratio=1:1". And about vmarginratio: "vertical margin ratio of top to bottom. The default ratio is 2:3". So, vcentering is about equating the top and bottom margins. By the way, in your test document, the vcentering=true option is overridden by the subsequent margin=2cm option. Of course, margin=2cm also equates the top and bottom margins. – Mico Sep 14 at 5:47
  • Yea, as I came to discover, it doesn't vertically centre the header, but rather, the text box – ifly6 Sep 14 at 5:52
2

To center the header block (height: \headheight) vertically within the top margin, you may want to run the following code:

\documentclass[12pt, b5paper]{article}
\usepackage{geometry}
\geometry{
    margin=2cm,
    headsep=\dimexpr1cm-0.5\headheight\relax,
    showframe % optional
}

This solution works by treating headsep as a quantity that's determined by tmargin (here: 2cm) and \headheight. The \headheight length variable can be adjusted as well, of course; e.g., set headheight=\baselineskip, before running headsep=\dimexpr1cm-0.5\headheight\relax,.

I've omitted the option vcentering=true that was in your code for two reasons: First, it's overridden by margin=2cm. Second, it doesn't achieve what you're looking to get done.

| improve this answer | |

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.