
Tenho o seguinte código para meu rodapé:
\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}
mas não está centralizado:
Como posso centralizá-lo? estou usando\documentclass[11pt,a4paper]{article}
Responder1
Use \\
e não \newline
. O comportamento é facilmente reproduzível:
\fbox{\parbox{5cm}{\centering A centered\\ text}}
\medskip
\fbox{\parbox{5cm}{\centering A centered\newline text}}
dá
Aqui está o código para você
\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}
O comando \\
muda de significado quando está em um \centering
contexto que está em vigor em \chead
, mas \newline
não.
Responder2
Defina o cabeçalho dentro de a tabular
, pois a quebra de linha (usando \newline
) não funciona conforme o esperado dentro das caixas de cabeçalho:
\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}