
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:
¿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
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}
El comando \\
cambia su significado cuando está en un \centering
contexto que está vigente en \chead
, mientras \newline
que 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:
\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}