[Tex/LaTex] Problems with positioning footers using fancyhdr

fancyhdrheader-footer

I'm having a problem placing footers on my document. On the first page it shows ok, but in the next pages it doesn't show at all. A bit of thinkering made me realize that the footer was indeed appearing, but out of page boundaries, so it wasn't visible. So the question is, how can I fix the height at which the footer is expected to appear? my code (part of it) is as follows:

\documentclass[10pt,letterpaper]{article}
.......
\usepackage[margin=4.5cm,headheight=28pt]{geometry}
\usepackage{fancyhdr}
.......
\hoffset-2.8cm
\voffset-2.3cm
\setlength{\textwidth}{18cm}
\setlength{\textheight}{22.5cm}
\renewcommand{\baselinestretch}{1.2} 
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
%\renewcommand{\footrulewidth}{0.3pt}
\fancyhead[C]{
    \hspace*{-1cm}\begin{tabular}{>{\centering\arraybackslash}p{3cm}b{12cm}>{\centering\arraybackslash}p{3cm}}
        % & \\[0.05ex]
        \hspace*{0.5cm}\includegraphics[width=2.5cm]{logo.png} & \hspace*{-2.5cm} Some random text I need... & \includegraphics[width=3cm]{LogoONAC.png} \\
    \end{tabular}   
}
\fancyfoot[C]{ - Some text I need to appear as footer on every page - }

Thanks in advance!

EDIT:

Ok, so I've reproduced my problem as suggested by Werner. The code is as follows:

\documentclass{article}

\usepackage[margin=1.5cm,headheight=10pt]{geometry}
\usepackage{fancyhdr,graphicx}
\usepackage{lipsum}
\usepackage{array}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\fancyhead[C]{
    \hspace*{-1cm}\begin{tabular}{>{\centering\arraybackslash}p{3cm}b{12cm}>{\centering\arraybackslash}p{3cm}}
        % & \\[0.05ex]
        \hspace*{0.5cm}\includegraphics[width=2.5cm]{logo.png} & \hspace*{-2.5cm}\begin{tabular}{>{\centering\arraybackslash}b{17cm}} \\[5ex] \textbf{XXXXXXXXXXXXXXXX}\\ \textbf{XXXXXXXXXXXXXXXXXXXXXXX}\\ \textbf{\footnotesize XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}\\ \end{tabular} & \includegraphics[width=3cm]{LogoONAC.png} \\
    \end{tabular}   
}

\fancyfoot[C]{ - OPERADOR - }

\begin{document}

\lipsum[1-20]

\end{document}

Best Answer

There are a couple of things that need to change in your code:

  • Don't set the page layout with geometry and then add other page layout settings manually. Do one or the other.

    I'd suggest using and sticking with only geometry and leave out settings like this:

    \hoffset-2.8cm
    \voffset-2.3cm
    \setlength{\textwidth}{18cm}
    \setlength{\textheight}{22.5cm}
    
  • You're probably trying to create a somewhat contradictory situation in terms of the page layout. Setting margin=4.5cm and having a \textwidth set to 22.5cm doesn't make it fit within a letterpaper size.

  • Listen to the warning issued by fancyhdr:

    Package Fancyhdr Warning: \headheight is too small (28.0pt): 
     Make it at least 116.60004pt.
     We now make it that large for the rest of the document.
     This may cause the page layout to be inconsistent, however.
    

    The value following "Make it at least ..." may differ depending on the size of the actual images you're including. This might be the root cause of your problem, as thing are adjusted for all pages following the first.

Here is a toned-down version of your example code where I've removed any manual setting of the page layout:

enter image description here

\documentclass{article}

\usepackage[margin=4.5cm,headheight=68pt]{geometry}
\usepackage{fancyhdr,graphicx}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\fancyhead[L]{\includegraphics[width=2.5cm]{example-image-a}\ Some random text I need...}
\fancyhead[R]{\includegraphics[width=3cm]{example-image-b}}
\fancyfoot[C]{ - Some text I need to appear as footer on every page - }

\begin{document}

\lipsum[1-20]

\end{document}
Related Question