Headers and Footers – Setting Logo Position in Header

geometryheader-footerlogospaper-size

I am using this code:

\rhead{\textsc{\includegraphics[height=36pt]{my_pict}}}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{40pt} 

to set a logo on the right hand of the header (I have also another one on the left).

It works nicely until I try to enlarge the text with

\usepackage[textwidth=17cm]{geometry}

the left logo seems still in a good position, while the right one get shifted towards the center.

How can I keep it bound to the right edge of the text?

here is the simplified version of the beginning of the file:

\documentclass[english]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}

\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{40pt} 

\lhead{\textsc{\includegraphics[height=36pt]{SciData_logo.jpg}}}
\rhead{\textsc{\includegraphics[height=36pt]{./paper_figures/OF_logo.png}}}


\usepackage[textwidth=17cm]{geometry}

\begin{document}
text
\end{document}

Thanks for help

Best Answer

Use \usepackage[textwidth=17cm]{geometry} to specify page dimension above \pagestyle{fancy}. Since it is a package that changes a relatively large number of parameters within the document, it should be included as one of the last or last packages to ensure that the settings have not been overwritten by one of the following packages.

With \usepackage{showframe} you can make page margins visible.

enter image description here

MWE:

\documentclass[english]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[textwidth=17cm]{geometry}

\pagestyle{fancy}
\fancyhf{}

\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{40pt} 

\lhead{\textsc{\includegraphics[height=36pt]{example-image-a}}}
\rhead{\textsc{\includegraphics[height=36pt]{example-image-b}}}


%\usepackage{showframe}
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}