1

I am trying to add a background color to the area between the bottom of the header to the top of the footer. But, somehow the whole page gets filled with the background color. Can someone explain it and tell how to do it?

I think the problem is the Background package but I don't know how to solve it or it there are any better solutions to add the custom background fill to every page.

Minimal working sample

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{background}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usepackage{tikzpagenodes}

% Background formatting
\backgroundsetup{%
    color=blue,
    angle=0,
    contents={%
        \begin{tikzpicture}[remember picture,overlay]%
            % Add background
            \fill[color = black!10] (current page header area.south west) rectangle (current page text area.south east);%
        \end{tikzpicture}%
    }%
}

\begin{document}

\section{Introduction}

\end{document}
  • 3
    Can you give a minimal working example? – nidhin Oct 31 '19 at 12:17
  • \fill[color = black!10] (current page header area.south west) rectangle (current page footer area.north east); works for me. – nidhin Oct 31 '19 at 12:26
  • @nidhin I will try, just a sec. – 7heViking Oct 31 '19 at 12:27
  • @nidhin, did you load any library? I got Package pgf Error: No shape named current page header area is known. ...k!10] (current page header area.south west) – Sigur Oct 31 '19 at 12:29
  • @Sigur tikzpagenodes – nidhin Oct 31 '19 at 12:31
1

Your approach works, but not with the background package (as you suspect). eso-pic also allows you to fill all pages, but does not have the problems background has.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{eso-pic}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}

% Background formatting
\AddToShipoutPictureBG{%
        \begin{tikzpicture}[remember picture,overlay]%
            % Add background
            \fill[color = black!10] (current page header area.south west) 
            rectangle (current page text area.south east);%
        \end{tikzpicture}%
    }%

\begin{document}

\section{Introduction}
\clearpage
\section{Summary}
\end{document}

enter image description here

| improve this answer | |
0

If you know the margins, you can shift the nodes.

enter image description here

\documentclass[11pt,a4paper]{report}
\usepackage[margin=2cm,showframe]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]%
    \fill[color = black!10] ([xshift=2cm,yshift=-2cm,yshift=\headsep]current page.north west) rectangle ([xshift=-2cm,yshift=2cm]current page.south east);%
\end{tikzpicture}%
\end{document}
| improve this answer | |
  • This doesn't work for me. I guess it might be be cause of the background package I am using to apply the color fill to all pages (but the title page). – 7heViking Oct 31 '19 at 12:37

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.