我的中心標題未居中

我的中心標題未居中

我的頁腳有以下程式碼:

\usepackage{fancyhdr}
\lhead{}
\rhead{}
\chead{My very important and long title that is not being centered as I would like to \newline Very Myself}
\cfoot{\thepage}
\setlength{\headheight}{14pt}

但它不居中:

在此輸入影像描述

我怎樣才能將它居中?我在用\documentclass[11pt,a4paper]{article}

答案1

使用\\與不使用\newline。該行為很容易重現:

\fbox{\parbox{5cm}{\centering A centered\\ text}}

\medskip

\fbox{\parbox{5cm}{\centering A centered\newline text}}

給出

在此輸入影像描述

這是適合您的程式碼

\documentclass{article}
\usepackage{geometry,fancyhdr}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\chead{%
  My very important and long title that is not being centered as I would like to \\ Very Myself
}
\cfoot{\thepage}
\setlength{\headheight}{24pt}
\begin{document}

\section{A section}
\end{document}

在此輸入影像描述

該命令\\在上下文中改變其含義\centering,該命令在 中有效\chead,而在 中則\newline不然。

答案2

將標題設為 a 內tabular,因為換行(使用\newline)在標題框中無法如預期般運作:

在此輸入影像描述

\documentclass{article}
\usepackage{geometry,fancyhdr}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\chead{\begin{tabular}{c}
  My very important and long title that is not being centered as I would like to \\ Very Myself
\end{tabular}}
\cfoot{\thepage}
\setlength{\headheight}{24pt}
\begin{document}
\section{A section}
\end{document}

相關內容