4

I am wanting to make a band of color that stretches across the entire page that will have contact information inside of it. I am attempting this using the color package, and \colorbox. I can not seem to get the band of color to begin at the left edge of the page. Is this possible with this package?

Here is an example of what I have tried:

\documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}

\begin{document}


\colorbox{cyan}{ \parbox{8.5in}{test} }

\end{document}
  • Welcome to TeX SX! Do you mean the whole width of the physical page? – Bernard Dec 21 '17 at 22:50
  • yes, I want it to basically "bleed" past the margins / full physical page width – hulud Dec 21 '17 at 23:15
4

You have to move the box left by \oddsidemargin+1in, besides taking into account \fboxsep.

\documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}
\usepackage{lipsum}

\begin{document}

\noindent\makebox[\textwidth][l]{%
  \hspace{-\dimexpr\oddsidemargin+1in}%
  \colorbox{cyan}{%
    \parbox{\dimexpr\paperwidth-2\fboxsep}{\lipsum[3]}%
  }%
}

\end{document}

enter image description here

2

The following code provides \insertcolorband{<colour>} that inserts a page-wide colour band using colour <colour>. The band is inserted in the background using eso-pic and requires at least 2 compilations on the first go (or with any change in the vertical position of the \insertcolorband macro):

enter image description here

\documentclass{article}

\usepackage{xcolor,eso-pic}
\usepackage[savepos]{zref}

\newcounter{colorband}
\newcommand{\insertcolorband}[1]{%
  \leavevmode\stepcounter{colorband}% New \insertcolorband
  \zsaveposy{cb-\thecolorband}% Mark y-position
  \edef\x{% Identify y-coordinate for storage
  \noexpand\AddToShipoutPictureBG*{% Place band in background of current page
    \noexpand\AtPageLowerLeft{% Marked from the lower-left corner of the page
      \noexpand\color{#1}% Band colour
      \noexpand\rule[\dimexpr\zposy{cb-\thecolorband}sp-.3\baselineskip]{\paperwidth}{\baselineskip}% Horizontal rule of height \baselineskip
    }%
  }}\x% Add content to background
}


\begin{document}

\sloppy% Just for this example
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus. 
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus 
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam. 
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum 
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius 
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.

\insertcolorband{cyan}%
test

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus. 
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus 
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam. 
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum 
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius 
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus. 
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus 
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam. 
\insertcolorband{green!20}%
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum 
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius 
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.

\end{document}
2

enter image description here

You need to account for the fboxsep padding at either end of the colorbox:

   \documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}

\begin{document}

text block

{\noindent\colorbox{cyan}{\makebox[\dimexpr\linewidth-2\fboxsep\relax]{test}}}

page

{\noindent\hspace*{\dimexpr-\oddsidemargin-1in\relax}%
 \colorbox{cyan}{\makebox[\dimexpr\paperwidth-2\fboxsep\relax]{test}}%
 \hspace*{-\paperwidth}}

\end{document}
  • You could use \parbox{\dimexpr\linewidth-2\fboxsep\relax}{test} rather than \makebox if you need multi-line content – David Carlisle Dec 21 '17 at 22:54
  • When I do this it is only text width not page width, I want the bar to extend to the edge of the page on either end. – hulud Dec 21 '17 at 23:07
  • @hulud oh that wasn't clear will update in a minute – David Carlisle Dec 21 '17 at 23:08
  • @hulud answer updated – David Carlisle Dec 21 '17 at 23:15

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.