[Tex/LaTex] Background boxes to the edges of the paper

colorpositioning

I am trying to produce a LaTeX template for a document format that was originally created in a WYSIWYG publishing program.

Part of the template requires some block colour background elements that span the full paperwidth.

There are two types of full width, block colour elements required:

  1. A fixed one in the header and footer
  2. A dynamically/positioned block that contains text. (Used for the abstract)

The crucial requirement is that these boxes have to fill the paper to both edges and also the top and bottom edges for those in the header/footer.

I cannot seem to replicate in LaTeX having tried various recipes with the tcolorbox and eso-pic packages.

Can this be done in LaTeX?

I have illustrated what I mean in this image

Best regards,

Alastair

Best Answer

I introduce \aty{y-location}{Text} for the headers and footers, which will be repeated on every page. Then I have \movingbox}{left text}{right text} for the box that can be placed where you want it. \inset is a length that defines the left/right indents of the colored boxes. Obviously, you can change the colors. The y location of the \aty box that you specify will depend on the height of the content you place in the box.

You will have to be careful that your header/footers do not overlap the text body.

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
\newlength\inset
\inset=1in\relax
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\movingbox[2]{{\centering\makebox[0pt]{%
  \colorbox{green!30!blue!40}{\parbox{\paperwidth}%
  {\leftskip=\inset\rightskip=\inset%
  \begin{minipage}[t]{\dimexpr.45\paperwidth-\inset}\strut#1\end{minipage}%
  \hspace{.1\paperwidth}%
  \begin{minipage}[t]{\dimexpr.45\paperwidth-\inset}\strut#2\end{minipage}%
  }}}\par}}
\newcommand\aty[2]{%
 \AddEverypageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#1\relax}{\colorbox{blue!20}{%
  \parbox{\paperwidth}{\leftskip=\inset\rightskip=\inset\strut#2}}}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\aty{.65in}{HEADER \lipsum[3]}
\aty{10.6in}{FOOTER \lipsum[4]}
\begin{document}
I will put the moving box below here

\movingbox{MOVING BOX \lipsum[5]}{RIGHT COLUMN STUFF \lipsum[6]}

\lipsum[1]
\end{document}

enter image description here