[Tex/LaTex] My center header is not centered

fancyhdrheader-footerhorizontal alignment

I have the following code for my 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}

but it is not centered:

enter image description here

How can I center it? I am using \documentclass[11pt,a4paper]{article}

Best Answer

Use \\ and not \newline. The behavior is easily reproducible:

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

\medskip

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

gives

enter image description here

Here's the code for you

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

enter image description here

The command \\ changes its meaning when in a \centering context, which is in force in \chead, whilst \newline doesn't.