Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to generate a latex report (via Sweave and R) where the header of the document is an image that covers everything (including the top/left/right page margin) and the footer covers everything (including the bottom/left/right page margin) such that the graphics for header and footer are flush to the page edges.

Kind of like this:

enter image description here

I've been playing around with fancyhdr but I can't seem to get it to do anything but stick out in the middle of the page. Additionally, I can't seem to get the header/footer to show up on ALL pages.

Help would be appreciated, here's where I am so far:

\documentclass[a4paper]{letter}
\usepackage{fancyhdr} 
\usepackage{lastpage}
\usepackage{float} 
\usepackage{graphicx}
\floatstyle{boxed} 
\restylefloat{figure} 
\pagestyle{fancy}

\begin{document}
\lhead{\includegraphics{documenthead.jpg}}
\lfoot{{\includegraphics{footer.jpg}}}
\rfoot{\thepage}
\title{Example Document}
\author{Author Name}
\date {\today}
\maketitle
\section{This is a good example}
Example text goes here \\
Repeat me to force a new page \\ 
\end{document}
share|improve this question

migrated from stackoverflow.com Jan 24 '12 at 0:55

This question came from our site for professional and enthusiast programmers.

2  
    
Thanks for that point prettygully –  Brandon Bertelsen Jan 24 '12 at 3:08

3 Answers 3

up vote 12 down vote accepted

I found a better solution using the wallpaper package, replacing foo and bar produces the desired result.

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{wallpaper}

\begin{document}
\ULCornerWallPaper{1}{foo}
\LLCornerWallPaper{1}{bar}
\lipsum[1-3]
\end{document}
share|improve this answer
    
This is perfect for what I wanted - thank you! –  Savara Dec 3 '12 at 11:50
    
Is there a simple way of putting say ULCornerWallPaper on odd pages, and URCornerWallPaper on even? –  ilya Sep 24 '13 at 16:48

If you are not stuck on using fancyhdr, you could adapt the solution from How do I add an image in the upper, left-hand corner using TikZ and graphicx which uses the background package:

enter image description here

Notes:

  • Need at least two runs to see the images.

Code:

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}
\usepackage[all]{background}

\usepackage{lipsum}
\usepackage{showframe}
\usepackage{tikz}

\newcommand{\MyGraphicLogo}{% For imported graphic logo
\begin{tikzpicture}[remember picture,overlay]
  \node at (current page.north) {\includegraphics[width=\paperwidth,height=4cm]{foo}};
  \node at (current page.south) {\includegraphics[width=\paperwidth,height=4cm]{bar}};
 \end{tikzpicture}
}

\SetBgContents{\MyGraphicLogo}% Select included image

\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo

\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-16]
\end{document}
share|improve this answer
    
Thanks Peter, this seems to get close to what I'm looking for. Could you help me in understanding where I utilize the names of the images. Would it be a simple matter of replacing foo and bar? –  Brandon Bertelsen Jan 24 '12 at 2:51
    
Actually, I figured that part out. Although I'm having problems with the positioning of the image. It seems to be that {current page.north west} puts the image in the top right but it is centered with the horizontal midpoint of the image is at the top edge of the page. –  Brandon Bertelsen Jan 24 '12 at 3:50
    
Yes foo and bar are the files names options to \includegraphics. You also need to remove the [demo] option when loading the graphicx package. Also, in my example I had used current page.north, but you can still use current page.north west and include [anchor=west] if you want the image to be on the top left hand side. –  Peter Grill Jan 24 '12 at 19:41
    
I had some problems with using the background package to place things on pages containing only floats. –  yo' Jan 25 '12 at 10:14
    
@tohecz: If that is not already a question on that issue it would be helpful to post one with a MWE. Off the top of my head I don't understand why that would be the case. –  Peter Grill Jan 25 '12 at 15:46

I think the command you are looking for is \fancyhfoffset. The left side seems needs to increase by \oddsidemargin + \hoffset + 1in and the right side needs to increase by \evensidemargin + \marginparwidth - \marginparsep (this is surprising to me I thought it would have been plus \marginparsep).

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{calc}

\fancypagestyle{plain}{%
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf{}
    \fancyhead[L]{\hrulefill{}}%
    \fancyhead[R]{\hrulefill{}}%
    \fancyfoot[L]{\hrulefill{}}%
    \fancyfoot[R]{\thepage}%
}

\fancyhfoffset[L]{\oddsidemargin + \hoffset + 1in}
\fancyhfoffset[R]{\evensidemargin + \marginparwidth - \marginparsep}

\pagestyle{plain}
\begin{document}
First page

\clearpage

Second page
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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