3

I am new to LaTeX and I am trying to place a rectangle (filled in red for instance) at the very top of all the pages of my document. The rectangle should be 0.5 cm high and with the page width.

I saw a lot of complicated threads to do that, but cannot manage to reproduce it.

My basic attempt by drawing a rectangle with \tikzpicture:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\fill[red] (0,0) rectangle (\paperwidth, 0.5cm)
\end{tikzpicture}
\end{document}

The problem is that LaTeX only starts drawing at the top left corner of the margin and not of the page. I tried to use \voffset but nothing changes.

1 Answer 1

4

Welcome to TeX SX! You don't really need TikZ for that: a simple coloured \rule will do, and the eso-pic package will let you insert what you want at any position in the page:

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{article}
\usepackage[texcoord]{eso-pic}
\usepackage[showframe]{geometry}
\usepackage{lipsum}
\AddToShipoutPictureBG{\AtPageUpperLeft{\color{Tomato}\rule[-5mm]{\paperwidth}{5mm}}}

\begin{document}

\lipsum

\end{document} 

enter image description here

2
  • Thanks Bernard, it works great ! Plus, I discovered new options. Note: I had to remove the option "showframe" in the geometry package. It crashed otherwise (maybe my distro does not support it). Jan 23, 2018 at 8:35
  • It's not your distribution, but probably you real code (or your real class) already loads geometry without this option, which is usually loaded for verification purpose, but isn't used in production.
    – Bernard
    Jan 23, 2018 at 9:38

You must log in to answer this question.

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