標題垂直居中

標題垂直居中

我有一份帶有此序言的文件:

\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{}

「頂部」中的文字未垂直居中。我如何將其垂直居中於 2 公分邊距(最好不計算適當的居中點)?

在此輸入影像描述

編輯:查看文檔,我認為vcentering它沒有達到我的期望。無論如何,有沒有辦法讓標題垂直居中?

答案1

要將標題區塊(高度\headheight:)在上邊距內垂直居中,您可能需要執行以下程式碼:

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

該解決方案的工作原理是將其視為由(此處:2cm)和headsep確定的數量。當然,長度變數也可以調整;例如,在運行之前設定。tmargin\headheight\headheightheadheight=\baselineskip,headsep=\dimexpr1cm-0.5\headheight\relax,

我省略了程式碼中的選項vcentering=true有兩個原因:首先,它被margin=2cm.其次,它沒有達到你想要完成的目標。

相關內容