我的页脚有以下代码:
\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}