2

I made a function that displays a header background. However, there supposed to be a horizontal line right under the background image, that goes from very left to very right with no margins.

This is my current code:

\documentclass{article}

\usepackage{lipsum}
\usepackage{wallpaper}

\newcommand{\BackgroundHeader}[3]{%
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{#1\paperwidth}{%
        \includegraphics[width=#1\paperwidth,height=#1\paperheight,%
                         keepaspectratio,trim={#2},clip]{#3}%
        \vfill%
      }
    }
  }
}

\begin{document}
\BackgroundHeader{2}{0 1650 550 1625}{background.png}
\lipsum[1-3]
\end{document}

And this is how it looks:

enter image description here

I've tried putting following under \vfill, but no results:

\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}%

What I'm doing wrong? How to get that line under the image?

  • 2
    \vfill puts it at the bottom of the page, doesn't it? If you colour it red, you can just see it on the edge of the page. – cfr Jul 13 '15 at 21:13
  • 1
    But also you have made the image twice \paperheight high. So the rule is going to be 2\paperheight down from the top of the page. – cfr Jul 13 '15 at 21:16
  • Maybe you want something like \newcommand{\BackgroundHeader}[3]{% \AddToShipoutPicture{% \AtPageLowerLeft{% \parbox[b][\paperheight]{#1\paperwidth}{% \includegraphics[width=#1\paperwidth,trim={#2},clip]{#3}% \par% \vfill \noindent\makebox[\paperwidth]{\color{red}\rule{\linewidth}{0.4pt}}% \bigskip \par }% }% }% }? – cfr Jul 13 '15 at 21:23
  • @cfr I think you should turn your comments into an answer :-) – Gonzalo Medina Jul 13 '15 at 22:52
  • @GonzaloMedina The trouble is, I'm not sure what it is meant to look like. How big should the background image really be and where should the line really go? – cfr Jul 13 '15 at 23:28
1

If the line should be under the header image you have to put it before \vfill:

enter image description here

Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{wallpaper}

\newcommand{\BackgroundHeader}[3]{%
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \parbox[b][\paperheight]{#1\paperwidth}{%
         \includegraphics[width=\linewidth,height=7\baselineskip
          ]{#3}% <- necessary to avoid spurious spaces
        \vspace*{-\baselineskip}
        \textcolor{red}{\rule[-2pt]{\paperwidth}{2pt}}%
        \vfill%
      }
    }
  }
}

\begin{document}
\BackgroundHeader{3}{}{example-image.pdf}
\lipsum[1-3]
\end{document}

Note that I have changed the options for \includegraphics because I do not have your picture.

If the image should be part of the page style you could also use package scrlayer, see Fancy header and footer including images with tikz

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.