Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to apply a different heading/border for each page. The footers will all be the same. I want it to look like this:

enter image description here

I can make the first two pages different but I don't know how to get subsequent pages to be different.

My code for the first two pages:

\documentclass[11pt]{article}

\usepackage[hmargin=1cm,bmargin=2cm,tmargin=2cm,centering]{geometry}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[rgb]{xcolor}
\usepackage{framed}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[none]{hyphenat}
\usepackage{parskip}

\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}

\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{atbegshi}

\newcommand\Header{%
  \begin{tikzpicture}[remember picture,overlay]
    \path [fill=boxgray]
      ([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
    \path [fill=card]
      (current page.north west) -- (current page.north east) --
      ([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
      ([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
  \node[font=\bfseries\color{white},anchor=east,
      xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
      {\fontsize{40}{60}\selectfont Newsletter};
  \end{tikzpicture}%
  }
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
  (current page.south west) -- (current page.south east) --
  ([yshift=-25pt]current page.south east|-current page text area.south east) --
  ([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
  \node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=10pt]current page.north east|-current page text area.north east) --
  ([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
  xshift=-.5cm,yshift=-1cm] at (current page.north east)
  {\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}

\pagestyle{empty}
\AtBeginShipout{\HeaderTwo\Footer}
\AtBeginShipoutFirst{\Header\Footer}


\begin{document}
\vspace*{2.cm}
%Page1leftbox
\begin{minipage}[t]{60mm}
    \centering
    \begin{minipage}[t]{.95\linewidth}
        Text...
    \end{minipage}
\end{minipage}\hfill
%Page1main
    \begin{minipage}[t]{.675\linewidth}
        \begin{center}
        \textbf{\Large Header1}
        \end{center}
        \parskip = 5pt
        \lipsum[1-4]
    \end{minipage}
    \clearpage
%Page2main
    \lipsum
\end{document}

and the code for the border for page 3:

\documentclass{article}
\usepackage[hmargin=1cm,bmargin=2cm,tmargin=2cm,centering]{geometry}
\usepackage{tikzpagenodes}
%\usetikzlibrary{calc}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{atbegshi}

\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{card}{RGB}{133,23,24}
\definecolor{bluey}{RGB}{0,121,194} 
\newcommand\Header{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
  ([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
  xshift=8cm,yshift=-6cm] at (current page.north east)
  {\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
  (current page.south west) -- (current page.south east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
  ([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
  (current page.south west) -- (current page.south east) --
  ([yshift=-25pt]current page.south east|-current page text area.south east) --
  ([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}

\pagestyle{empty}
\AtBeginShipoutFirst{\Header\Footer}

\begin{document}
    \begin{minipage}[t]{.65\linewidth}
        \vspace{10pt}
        \begin{multicols}{2}
            \lipsum[1-6]
        \end{multicols}
    \end{minipage}
\end{document}
  • How can I combine them all in to one document with the potential for more pages with different designs?
  • This code seems to generate a blank page at the end of the document. Why? and how do I stop that?
share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

One possibility using the background package:

\documentclass{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{ifthen}
\usepackage[
  scale=1,
  opacity=1,
  angle=0
]{background}

% command for modular arithmetic
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}

% definitions of colors to be used
\definecolor{color1}{RGB}{11,64,176}% blue
\definecolor{color2}{RGB}{133,23,24}% red
\definecolor{color3}{RGB}{107,107,107}% red

% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color1]
  ([yshift=20pt]current page.south west)
    rectangle
  (current page.south east);
\end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 0
\newcommand\Headerz{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
  (current page.north west) --
  (current page.north east) --
  (current page.east) --
  ([xshift=-50pt,yshift=-25pt]current page.north east) --
  ([yshift=-25pt]current page.north west) --
  cycle;
\fill[color3]
  (current page.east) --
  ([xshift=-50pt,yshift=20pt]current page.south east) --
  ([yshift=20pt]current page.south east) --
  cycle;    
\end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 1
\newcommand\Headero{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
  (current page.north west) --
  (current page.north east) --
  ([yshift=-70pt]current page.north east)
      to[out=160,in=20]
  ([yshift=-70pt]current page.north west) --
  cycle;
\end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 2
\newcommand\Headert{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
  (current page.north west)
     rectangle
  ([yshift=-25pt]current page.north east);
\end{tikzpicture}%
}

% include common footer
\backgroundsetup{contents=\Footer}

% add header depending on the value of the page modulo 3
\AddEverypageHook{%
  \ifthenelse{\modulo{\value{page}}{3}=0}
    {\backgroundsetup{contents={\Headerz}}}
    {%
      \ifthenelse{\modulo{\value{page}}{3}=1}
        {\backgroundsetup{contents={\Headero}}}
        {%
          \ifthenelse{\modulo{\value{page}}{3}=2}
            {\backgroundsetup{contents={\Headert}}}
            {}
        }%
    }
  \BgMaterial
}

\begin{document}

text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text

\end{document}

enter image description here

The idea is to define as many different decorations you want for the headers and then to include them conditionally depending on modular arithmetic for the page counter; schematically

if the residue of the page number modulo 3 is zero 
    use \Headerz as background
else if the residue of the page number modulo 3 is one
    use \Headero as background
else if the residue of the page number modulo 3 is two
    use \Headert as background
fififi

Obviously this easily generalizes to an arbitrary number of different headers.

Here's a version using the decorations from the code in the question:

\documentclass{article}
\usepackage[
  hmargin=1cm,
  bmargin=2cm,
  tmargin=2cm,
  centering
]{geometry}
\usepackage{ifthen}
\usepackage{tikzpagenodes}
\usepackage[
  scale=1,
  opacity=1,
  angle=0,
  contents={}
]{background}

% command for modular arithmetic
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}

% definitions of colors to be used
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}

% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
  (current page.south west) -- (current page.south east) --
  ([yshift=-25pt]current page.south east|-current page text area.south east) --
  ([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
  \node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 0
\newcommand\Headerz{%
  \begin{tikzpicture}[remember picture,overlay]
    \path [fill=boxgray]
      ([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
    \path [fill=card]
      (current page.north west) -- (current page.north east) --
      ([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
      ([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
  \node[font=\bfseries\color{white},anchor=east,
      xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
      {\fontsize{40}{60}\selectfont Newsletter};
  \end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 1
\newcommand\Headero{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=10pt]current page.north east|-current page text area.north east) --
  ([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
  xshift=-.5cm,yshift=-1cm] at (current page.north east)
  {\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}

% header for pages congrunent with 3 modulo 2
\newcommand\Headert{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
  ([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
  xshift=8cm,yshift=-6cm] at (current page.north east)
  {\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
  (current page.south west) -- (current page.south east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
  ([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}

% add header depending on the value of the page modulo 3
\AddEverypageHook{%
  \ifthenelse{\modulo{\value{page}}{3}=0}
    {\backgroundsetup{contents={\Headerz}}}
    {%
      \ifthenelse{\modulo{\value{page}}{3}=1}
        {\backgroundsetup{contents={\Headero}}}
        {%
          \ifthenelse{\modulo{\value{page}}{3}=2}
            {\backgroundsetup{contents={\Headert}}}
            {}
        }%
    }
  \BgMaterial
}

% add footer
\AddEverypageHook{%
  \backgroundsetup{contents={\Footer}}  
  \BgMaterial
}  

\pagestyle{empty}

\begin{document}

text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text\clearpage 
text

\end{document}

enter image description here

To do the conditional tests I borrowed the \modulo macro defined by egreg in his answer to How do I calculate n modulo 3 in LaTeX?.

If the backgrounds are not supposed to cycle through the pages, but every page must have its own decoration, you need to define as many decorations as pages in the document and then the code simplifies since a simple conditional test depending on the value of the page counter decides the background: A simple example with four backgrounds (I designed a quick decoration \HeadeFour for the fourth page):

\documentclass{article}
\usepackage[
  hmargin=1cm,
  bmargin=2cm,
  tmargin=2cm,
  centering
]{geometry}
\usepackage{tikzpagenodes}
\usepackage[
  scale=1,
  opacity=1,
  angle=0,
  contents={}
]{background}

% definitions of colors to be used
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}

% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
  (current page.south west) -- (current page.south east) --
  ([yshift=-25pt]current page.south east|-current page text area.south east) --
  ([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
  \node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}

% header for page one
\newcommand\HeaderOne{%
  \begin{tikzpicture}[remember picture,overlay]
    \path[fill=boxgray]
      ([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
    \path [fill=card]
      (current page.north west) -- (current page.north east) --
      ([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
      ([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
  \node[font=\bfseries\color{white},anchor=east,
      xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
      {\fontsize{40}{60}\selectfont Newsletter};
  \end{tikzpicture}%
}

% header for page two
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=10pt]current page.north east|-current page text area.north east) --
  ([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
  xshift=-.5cm,yshift=-1cm] at (current page.north east)
  {\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}

% header for page three
\newcommand\HeaderThree{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
  (current page.north west) -- (current page.north east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
  ([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
  xshift=8cm,yshift=-6cm] at (current page.north east)
  {\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
  (current page.south west) -- (current page.south east) --
  ([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
  ([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
  ([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}

% header for page four
\newcommand\HeaderFour{%
\begin{tikzpicture}[remember picture,overlay]
\fill[boxgray]
      ([xshift=-1cm]current page.north east) -- ([xshift=-4cm]current page.north east) -- ([xshift=-4cm]current page.south east) -- ([xshift=-1cm]current page.south east) -- cycle;
\fill[card]
  (current page.north west) -- 
  (current page.north east) --
  ([yshift=-40pt]current page.north east|-current page text area.north east)
    to[out=160,in=20]
  ([yshift=-40pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
  xshift=-.5cm,yshift=-1cm] at (current page.north east)
  {\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}


% add header depending on the value of the page modulo 3
\AddEverypageHook{%
  \ifnum\value{page}=1\relax
    \backgroundsetup{contents={\HeaderOne}}
  \else  
  \ifnum\value{page}=2\relax
    \backgroundsetup{contents={\HeaderTwo}}
  \else  
  \ifnum\value{page}=3\relax
    \backgroundsetup{contents={\HeaderThree}}
  \else  
  \ifnum\value{page}=4\relax
    \backgroundsetup{contents={\HeaderFour}}
  \fi\fi\fi\fi
  \BgMaterial
}

\AddEverypageHook{%
  \backgroundsetup{contents=\Footer}
  \BgMaterial
}

\pagestyle{empty}

\begin{document}

text\clearpage 
text\clearpage 
text\clearpage 
text

\end{document}

enter image description here

The \clearpage commands in my example are just for brevity's sake (to quickly produce several pages); they are not really needed in a real document with real content.

share|improve this answer
    
Thanks for all the options, it works. However, how can I make the footer go on top of the decoration? I want a bottom blue bar on all the pages, not this weird overlap from the shapes. Also, what does \fi do in the \AddEverypageHook command? –  TLC Apr 23 at 0:04
1  
@TLC You're welcome. Please see my updated answer. \fi is the closing delimiter for all TeX conditionals; in my code I used four \ifnums, so one has to use four \fis. –  Gonzalo Medina Apr 23 at 0:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.