
Ich habe den folgenden Code für meinen Footer:
\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}
aber es ist nicht zentriert:
Wie kann ich es zentrieren? Ich verwende\documentclass[11pt,a4paper]{article}
Antwort1
Verwenden Sie \\
und nicht \newline
. Das Verhalten ist leicht reproduzierbar:
\fbox{\parbox{5cm}{\centering A centered\\ text}}
\medskip
\fbox{\parbox{5cm}{\centering A centered\newline text}}
gibt
Hier ist der Code für Sie
\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}
Der Befehl \\
ändert seine Bedeutung in einem \centering
Kontext, der in gültig ist \chead
, während \newline
dies nicht der Fall ist.
Antwort2
Setzen Sie die Kopfzeile in ein tabular
, da der Zeilenumbruch (mit \newline
) in den Kopfzeilenfeldern nicht wie erwartet funktioniert:
\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}