1

So, I want a picture in my page headers, and one in my footer. This is the code I have:

\documentclass[12pt,a4paper,oneside,article]{memoir}
\usepackage{lipsum} % for lipsum text
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\AddToShipoutPictureBG{%
\AtPageUpperLeft{\raisebox{-\height}{\hspace{105pt}\includegraphics[width=\textwidth,height=3cm]{example-image-a}}}%
}

\AddToShipoutPictureBG{%
\AtPageLowerLeft{\hspace{445pt}\includegraphics[width=1.5cm,height=1.5cm]{example-image-b}}%
}

\begin{document}
\lipsum[1-7]
\end{document}

As you can see, there is no margin above and below the pictures:

Header

Footer

How can I remedy this? Bonus point for showing an alternative to my awful hspace solution!

  • 1
    ...bonus points? But how? ;) – Werner Jan 21 at 19:46
1

Since you're using memoir in oneside mode, the left-margin space should be given by \spinemargin:

enter image description here

\documentclass[oneside]{memoir}

\usepackage{lipsum} % for lipsum text
\usepackage{eso-pic,graphicx}

\AddToShipoutPictureBG{%
  \AtPageUpperLeft{%
    \raisebox{\dimexpr-\height-5pt}{\hspace{\spinemargin}\includegraphics[width=\textwidth,height=3cm]{example-image-a}}%
  }
  \AtPageLowerLeft{%
    \raisebox{12pt}{%
      \hspace{\dimexpr\spinemargin+\textwidth}\makebox[0pt][r]{\includegraphics[width=1.5cm,height=1.5cm]{example-image-b}}%
    }
  }%
}

\begin{document}

\lipsum[1-7]

\end{document}

Above I've dropped (negative raise) the header image by an additional 5pt and raised the footer image by 12pt. You can adjust this as necessary.

2

Why not just use the header and footer commands of the memoir class?

mwe

\documentclass[12pt,a4paper,oneside]{memoir}
\usepackage{lipsum}
\usepackage{graphicx}
\topmargin\dimexpr-1in+1em\headheight3cm\headsep1em\footskip\dimexpr1.5cm+1em
\makeoddhead{plain}{}{\includegraphics[width=\textwidth,height=\headheight]{example-image-a}}{}
\makeoddfoot{plain}{}{}{\includegraphics[width=1.5cm,height=1.5cm]{example-image-b}}
\pagestyle{plain}
\begin{document}
\lipsum[1-17]
\end{document}

Or more accordingly to the memoir way:

\documentclass[12pt,a4paper,oneside]{memoir}
\usepackage{lipsum}
\usepackage{graphicx}
\setulmarginsandblock{4.5cm}{4cm}{*}
\setheadfoot{3cm}{1cm}
\setlength{\footskip}{2.5cm}
\checkandfixthelayout
\makeoddhead{plain}{}{\includegraphics[width=\textwidth,height=\headheight]{example-image-a}}{}
\makeoddfoot{plain}{}{}{\includegraphics[width=1.5cm,height=1.5cm]{example-image-b}}
\pagestyle{plain}
\begin{document}
\lipsum[1-17]
\end{document}
1
  1. Change the value of the first argument of \raisebox
  2. replace \AtPageUpperLeft with \AtTextUpperLeft to avoid using \hspace for the header.
  3. for the footer: define a \newlength{\footerhspace} equal to \textwidth minus the picture width.

!

\documentclass[12pt,a4paper,oneside,article]{memoir}
\usepackage{lipsum} % for lipsum text
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{calc}

\newlength{\footerhspace}
\setlength{\footerhspace}{\textwidth-1.5cm}

\AddToShipoutPictureBG{%
\AtTextUpperLeft{\raisebox{0.25\height}{\includegraphics[width=\textwidth,height=3cm]{example-image-a}}}%
}

\AddToShipoutPictureBG{%
\AtTextLowerLeft{\raisebox{-2\height}{\hspace{\footerhspace}\includegraphics[width=1.5cm,height=1.5cm]{example-image-b}}}%
}
\begin{document}
\lipsum[1-7]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.