我的中心标题不居中

我的中心标题不居中

我的页脚有以下代码:

\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

在 内设置标题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}

相关内容