Graphics, Figures & TablesRotative background image and font color

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sombrancelha
Posts: 22
Joined: Fri May 18, 2007 6:48 pm

Rotative background image and font color

Post by sombrancelha »

Hello,

I'm making a document with 4 background images: for each page, I have a different one. So pages 1,5,9,13 have the same image, 2,6,10,14, another, and so on.

I'm currently doing this manually, but not only does this pollutes the code, but also is very tiring and boring. I would like to know if it's possible to automatize it.

Also, for each background, I use a different font color. And I'm also doing this manually. This is even worse, because I have to set precisely where I want it to start.

My code:

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage[brazil]{babel}
\usepackage[vmargin={5.5cm, 7cm},hmargin={3.5cm, 4.6cm}]{geometry}
\usepackage{graphicx,color}

\usepackage{eso-pic}

%Define background images
\newcommand\BackgroundBlue{
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{Blue.png}%
\vfill
}}}

\newcommand\BackgroundRed{
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{Red.png}%
\vfill
}}}

\newcommand\BackgroundGreen{
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{Green.png}%
\vfill
}}}

\newcommand\BackgroundViolet{
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{Violet.png}%
\vfill

%Define colors
[code]\definecolor{Blue}{rgb}{0.19,0.52,0.61}
\definecolor{Red}{rgb}{0.58,0.21,0.20}
\definecolor{Green}{rgb}{0.46,0.57,0.24}
\definecolor{Violet}{rgb}{0.37,0.29,0.48}

}}}

\begin{document}
\AddToShipoutPicture*{\BackgroundBlue}
\color{Blue}

Page 1

\newpage
\AddToShipoutPicture*{\BackgroundRed}
\color{Red}

Page 2

\newpage
\AddToShipoutPicture*{\BackgroundGreen}
\color{Green}

Page 3

\newpage
\AddToShipoutPicture*{\BackgroundViolet}
\color{Violet}

Page 4

\newpage

\AddToShipoutPicture*{\BackgroundBlue}
\color{Blue}

Page 5 - Same font color and background of Page 1

\end{document}
Please note that I don't have \newpage everywhere, I only put it here to show easier the effect.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Rotative background image and font color

Post by gmedina »

Hi,

in the following example code I defined the \mycpage command that could help you. It retrieves the "true" page number and depending on its remainder when divided by four performs certain action (sets a background color for the page, in my example).

Now all you have to do is to use the \mycpage command ate least one time in every page of your document. A little example:

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{xcolor}
\usepackage{intcalc}
\usepackage{refcount}

%%%%%%
%Define colors
\definecolor{Blue}{rgb}{0.19,0.52,0.61}
\definecolor{Red}{rgb}{0.58,0.21,0.20}
\definecolor{Green}{rgb}{0.46,0.57,0.24}
\definecolor{Violet}{rgb}{0.37,0.29,0.48}

% the main command
\newcounter{pl}
\newcounter{tp}
\newcommand\pagemod{}
\newcommand\mycpage{%
  \stepcounter{pl}
  \label{pl-\thepl}
  \setcounterpageref{tp}{pl-\thepl}
  \renewcommand\pagemod{\intcalcMod{\thetp}{4}}
  \ifnum\pagemod = 1
    \pagecolor{Blue}
  \else
  \ifnum\pagemod = 2
    \pagecolor{Red}
  \else
  \ifnum\pagemod = 3
    \pagecolor{Green}
  \else
  \ifnum\pagemod = 0
    \pagecolor{Violet}
  \fi\fi\fi\fi
}
%%%%%%

% just to produce text for the example
\newcommand\dummytext{text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text\par}

\begin{document}

\dummytext\mycpage\dummytext\dummytext\dummytext\dummytext\dummytext\dummytext
\dummytext
\dummytext\mycpage\dummytext\dummytext\dummytext\dummytext\dummytext\dummytext
\dummytext
\dummytext\mycpage\dummytext\dummytext\dummytext\dummytext\dummytext\dummytext
\dummytext
\dummytext\mycpage\dummytext\dummytext\dummytext\mycpage\dummytext\dummytext\dummytext
\dummytext\dummytext\dummytext
\dummytext\dummytext\mycpage\dummytext\dummytext\dummytext
\dummytext\dummytext\dummytext\dummytext\dummytext\mycpage\dummytext\dummytext\dummytext
\dummytext\dummytext\dummytext\dummytext\mycpage\dummytext

\end{document}
Edit: by using the \everypar and \shipout TeX primitives you can dispense the explicit use of the \mycpage command (if the last page contains only remains from a paragraph from the previous page, you'll have to use the command, though):

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{xcolor}
\usepackage{intcalc}
\usepackage{refcount}
\usepackage{lipsum}% just to produce text for the example

%%%%%%
%Define colors
\definecolor{Blue}{rgb}{0.19,0.52,0.61}
\definecolor{Red}{rgb}{0.58,0.21,0.20}
\definecolor{Green}{rgb}{0.46,0.57,0.24}
\definecolor{Violet}{rgb}{0.37,0.29,0.48}

% the main command
\newcounter{pl}
\newcounter{tp}
\newcommand\pagemod{}
\newcommand\mycpage{%
  \stepcounter{pl}
  \label{pl-\thepl}
  \setcounterpageref{tp}{pl-\thepl}
  \renewcommand\pagemod{\intcalcMod{\thetp}{4}}
  \ifnum\pagemod = 1
    \pagecolor{Blue}
  \else
  \ifnum\pagemod = 2
    \pagecolor{Red}
  \else
  \ifnum\pagemod = 3
    \pagecolor{Green}
  \else
  \ifnum\pagemod = 0
    \pagecolor{Violet}
  \fi\fi\fi\fi
}
%%%%%%


\begin{document}

\everypar{\shipout\box255\mycpage}

\lipsum[1-90]\mycpage

\end{document}
Reagrding the font color issue, I will think about a way to automate it too.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply