3

I'd like to have a colored box in the upper part of every page. Even though it's a simple task, I cannot make it work. Having looked for answers here and in the eso-pic package discription does not bring me any further.

Neither playing around with minipages as suggested here http://en.wikibooks.org/wiki/LaTeX/Tips_and_Tricks#Sidebar_with_information has solved it.

This is what I came up with so far:

\documentclass[12pt,a5paper]{article}
\usepackage{geometry}
\usepackage{eso-pic,xcolor,lipsum}
\pagestyle{empty}

\AddToShipoutPictureBG{
    \AtPageUpperLeft{
        {\color{red}%
            \rule[-1cm]%offset PageBorder
                {\paperwidth}%{14.8cm}
                {1cm}%height
        }
    }
}

\begin{document}
\lipsum
\end{document}

When I run pdfLaTeX, I always have a small gap, say .1mm on the left border. Did not dare to try that How to I reduce space before and after HRule? , though.

Any help is greatly appreciated.

lactea
  • 137
  • 1
  • 7
  • 1
    Welcome to the site! Your question is excellent, thank you for providing a complete MWE, it really helps :) Nice indentation, too :) Welcome! – cmhughes Jun 11 '14 at 19:42
  • Thank you @cmhuges. I've already asked a question about a year ago, cannot recall the login, though. Nevertheless, I have an account on ask.libreoffice on the same nickname. – lactea Jun 11 '14 at 19:44
  • you're missing a % symbol: \AtPageUpperLeft{% – cmhughes Jun 11 '14 at 19:45
  • Wow, that was quick, thank you! How come % actually has a function? I've thought it is used for marking comments, only.

    Anyhow, there are still two questions; (1) Would you solve the issue in a more elegant way and (2) can you mark this as an answer for me to give you points?

    – lactea Jun 11 '14 at 19:50
  • have a look at What is the use of percent signs (%) at the end of lines? :) Thanks for the offer of rep points, but Herbert has already provided an answer which covers it :) – cmhughes Jun 11 '14 at 20:05

1 Answers1

3
\AddToShipoutPictureBG{%
    \AtPageUpperLeft{%
        {\color{red}%
            \rule[-1cm]%offset PageBorder
                {\paperwidth}%{14.8cm}
                {1cm}%height
        }%
    }%
}

If you are not sure then put at every line end the comment character % to avoid trailing spaces. A linebreak is internally replaced by a space. However, in your example the one at \AtPageUpperLeft{% is only important.

  • Thank you too @Herbert for solving this! I did not know about trailing spaces. Great you have pointed that out! – lactea Jun 11 '14 at 19:54