Mi encabezado central no está centrado

Mi encabezado central no está centrado

Tengo el siguiente código para mi pie de página:

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

pero no está centrado:

ingrese la descripción de la imagen aquí

¿Cómo puedo centrarlo? estoy usando\documentclass[11pt,a4paper]{article}

Respuesta1

Usar \\y no \newline. El comportamiento es fácilmente reproducible:

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

\medskip

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

da

ingrese la descripción de la imagen aquí

Aquí está el código para ti

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

ingrese la descripción de la imagen aquí

El comando \\cambia su significado cuando está en un \centeringcontexto que está vigente en \chead, mientras \newlineque no.

Respuesta2

Establezca el encabezado dentro de a tabular, ya que el salto de línea (usando \newline) no funciona como se esperaba dentro de los cuadros del encabezado:

ingrese la descripción de la imagen aquí

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

información relacionada