6

Using the leaflet package, I am trying to create a flyer for a document. I have specified the background color NavyBlue for pages 1, 2, 4, and 5. Unfortunately, the default text color, black, is difficult to read on that background. To fix that, I would like to use the color, white. However, I must only use that color on pages 1, 2, 4, and 5. It would not show up on the other, white pages. How can I accomplish this in LaTeX?

Below is a sample file:

\documentclass[letterpaper]{leaflet}
\usepackage[dvipsnames]{xcolor}
\usepackage{blindtext}

\title{Sample Document}
\author{Anonymous}
\date{\today}

\AddToBackground{1}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{2}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{4}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{5}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}

\begin{document}
\maketitle

\Blinddocument

\end{document}
5

tcolorbox package can apply different options to each fragment from a broken box. Then it's possible to include all text from the leaflet inside a breakable, blankest tcolorbox (blankest doesn't change paragraph format) and as every fragment is identified with a particular number, we can use it to fix the color of the text.

\documentclass[letterpaper]{leaflet}
\usepackage[dvipsnames]{xcolor}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\title{Sample Document}
\author{Anonymous}
\date{\today}

\AddToBackground{1}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{2}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{4}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}
\AddToBackground{5}{
  \put(0,0){\textcolor{NavyBlue}{\rule{\paperwidth}{\paperheight}}}}

\begin{document}

% White color for `title` is forced.
{\color{white}\maketitle}

% A breakable blankest colorbox with an `extras` option which is evaluated  
% on each fragment identified by a `\thetcolorboxnumber` 
\begin{tcolorbox}[breakable, blankest, 
      code={\newcommand{\mytextcolor}{%
          \ifnum\thetcolorboxnumber=3 black%
          \else\ifnum\thetcolorboxnumber=6 black%
          \else white\fi\fi}},
      extras = {colupper=\mytextcolor}
]
\Blinddocument
\end{tcolorbox}

\end{document}

enter image description here

  • This is a very clever solution! :-) – Thomas F. Sturm Sep 22 '16 at 6:14
  • @ThomasF.Sturm Nice to hear it! By the way, is this the correct way of using code and extras? – Ignasi Sep 22 '16 at 6:44
  • Yes, I think so. – Thomas F. Sturm Sep 22 '16 at 6:51

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.