3

I try to align things in my header&footer. Here's what I have:

\documentclass{extarticle}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\geometry{a4paper} 
\geometry{top=25mm}
\geometry{bottom=25mm}
\geometry{left=20mm}
\geometry{right=20mm}
\pagestyle{fancy}
\fancyhead[C]{}
\fancyhead[L]{\large Theme of my document}
\fancyhead[R]{\includegraphics[scale=0.1]{example-image-a}}
\fancyfoot[L]{\includegraphics[scale=0.07]{example-image-a}}
\fancyfoot[R]{\large\thepage}
\fancyfoot[C]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
    \lipsum[1-2]
\end{document}

it gives me this for header:

default alignment for header

and this for footer:

default alignment for footer

But I want to align the header this way (center of text on the same level as the center of the picture)

target for header

And I want to slightly move down picture in the footer so that it can be aligned for eg like this:

target for footer

How do I do this? I tried some hard-coding solutions like \vspace and \rule with 0 width, but it all did not work.

1
  • 4
    unrelated but don't do \geometry{a4paper} \geometry{top=25mm} \geometry{bottom=25mm} \geometry{left=20mm} \geometry{right=20mm} set them all in the same call as comma separated values, then geometry will see all the settings and can do consistency checks Commented Jul 28 at 18:03

3 Answers 3

4

You can use \raisebox to raise (or lower) the image:

\documentclass{extarticle}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\geometry{a4paper} 
\geometry{top=25mm}
\geometry{bottom=25mm}
\geometry{left=20mm}
\geometry{right=20mm}
\pagestyle{fancy}
\fancyhead[C]{}
\fancyhead[L]{\large Theme of my document}
\fancyhead[R]{\raisebox{-0.3cm}{\includegraphics[scale=0.1]{example-image-a}}}
\fancyfoot[L]{\raisebox{-0.15cm}{\includegraphics[scale=0.07]{example-image-a}}}
\fancyfoot[R]{\large\thepage}
\fancyfoot[C]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\setlength{\headheight}{24.1pt}
\begin{document}
    \lipsum[1-2]
\end{document}
2
4

It's easy with adjustbox. You also need, as advised by fancyhdr, to increase the head height.

\documentclass{extarticle}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\geometry{
  a4paper,
  top=25mm,
  bottom=25mm,
  left=20mm,
  right=20mm,
  headheight=24.1pt,
}

\pagestyle{fancy}
\fancyhf{}% clear all
\fancyhead[L]{\large Theme of my document}
\fancyhead[R]{\includegraphics[scale=0.1,valign=c]{example-image-a}}
\fancyfoot[L]{\includegraphics[scale=0.07,valign=c]{example-image-a}}
\fancyfoot[R]{\large\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

\lipsum[1-2]

\end{document}

output a4 paper

Here's the same with a6paper that shows more clearly the alignments.

output a6 paper

1
  • indeed very easy, thank you for your answer! Commented Jul 29 at 12:08
1

With scrlayer-scrpage the vertical centering would already be the default:

\documentclass{extarticle}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum,xcolor}
\usepackage{geometry}
\usepackage{graphicx}

\geometry{
  a4paper,
  top=25mm,
  bottom=25mm,
  left=20mm,
  right=20mm,
  headheight=28.3pt,
}

\clearpairofpagestyles
\setlength{\footheight}{20.5pt}
\setkomafont{pagehead}{\normalfont\large}
\ihead{Theme of my document}
\ohead{\includegraphics[scale=0.1]{example-image-a}}
\ifoot{\includegraphics[scale=0.07]{example-image-b}}
\ofoot*{\pagemark}

\cfoot{\color{red}\hrulefill}% for demonstration: visualization of base line
\chead{\color{red}\hrulefill}% for demonstration: visulaization of base line
  
\begin{document}

\lipsum[1-2]

\end{document}

page header with vertically centered image

page footer with vertically centered image

I've added the two red lines (using \chead and \cfoot) only for demonstration. For real separation lines, I would recommend to use option headsepline resp. footsepline instead. See the manual for more information.

Option headheight has been added corresponding to the head height warning of scrlayer-scrpage. Analogues increase of \footheight has been added corresponding to the foot height warning of scrlayer-scrpage.

One additional off-topic note about using extarticle: The class is not in sync with changes of article class since end of 1996. The default font size of extarticle is the same as of article: 10pt. For 10pt, 11pt, 12pt I would recommend to use article instead of extarticle.

The other geometry options have been combined into one call of \geometry, to allow the package to do some plausibility checks (e.g. for over specification).

1
  • Never heard of this package before, so thanks for telling about it! Commented Jul 29 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .