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.

Using Latex

I need to set my headers and footers on a page by page by basis pending the contents of the page. For example if the page contains

(A) then the header and footer needs to say Apple

If the page contains

(B) then the header and footer needs to say Bravo

Hierarchy for example is (B) is more important than (A). If (B) and (A) are on the same page it needs to always say Bravo on the pages where both are there. If it is just (A) on the page Apple is fine.

Is there an easy way to do this in my style/headers? If not, what path should I be looking down?

Example Code for how it should look like

\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
    \setlength{\headheight}{1in}
    \fancyhf{}
    \fancyhead[C]{\bfseries{\Large BRAVO}}
    \fancyfoot[C]{\thepage \\ \bfseries{\Large BRAVO}}
    (A)\Blindtext[1]

    (B)\Blindtext[1]

    (A)\Blindtext[1]

    (A)\Blindtext[1]
    \fancyhead[C]{\bfseries{\Large APPLE}}
    \fancyfoot[C]{\thepage \\ \bfseries{\Large APPLE}}
    (A)\Blindtext[1]
    (A)\Blindtext[1]
    (A)\Blindtext[1]
    (A)\Blindtext[1]
\end{document}
share|improve this question
    
You simply need suitable \mark comands. But without informations about your style, it is impossible to be more exact. You even didn't mention if you are using latex or plain or context or something else. –  Ulrike Fischer Feb 12 '13 at 16:09
    
I'm using Latex. Updated my explanation on hierarchy in the main body. What about setting Hierarchy? –  Eric Feb 12 '13 at 16:23
1  
Make an example that shows your actual code. Also describe what should happen if you have more than one entry of each type. –  Ulrike Fischer Feb 12 '13 at 16:29
    
I added a a minimum working example to show how I want it to work/look. You can see on the first page where (B) is introduced the page says Bravo at the top and bottom. On the other pages where there is no (B) and only (A) it just says Apple. I want to automate this since the actual documents tend to be 100+ pages. –  Eric Feb 12 '13 at 16:35
add comment

2 Answers

This gives the output you described. But I do have some doubts that it is really what you are after.

\documentclass[12pt, a4paper]{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\leftmark}
\fancyfoot[C]{\thepage --\leftmark}   
\usepackage{afterpage} 
\begin{document}
\markboth{Apple}{Apple}%Initialize to Apple
(A)\Blindtext[1]

(B)\markboth{Bravo}{Bravo}\afterpage{\markboth{Apple}{Apple}}\Blindtext[1]

(A)\Blindtext[1]

(A)\Blindtext[1]
(A)\Blindtext[1]
(A)\Blindtext[1]
(A)\Blindtext[1]
(A)\Blindtext[1]
\end{document}
share|improve this answer
    
Thanks, I did it slightly differently so I could use less packages and handle a few more odd cases. Thank you! –  Eric Feb 12 '13 at 19:13
add comment

I went ahead and it did it slightly different since I didn't want to use marks etex or etoolbox. It leaves the main code a bit more clean IMO. I'm pretty sure the function could be cleaned up significantly, but for now I think this will work for me.

\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{fancyhdr}

\pagestyle{fancy}
\usepackage{xstring}

\newcommand{\pageclass}{}

\makeatletter
    \newcounter{pagerank}
    \newcounter{thispage}
    \setcounter{thispage}{0}
    \newcounter{rank}
    \newcommand\setClass[1]{
        \setcounter{rank}{0}
        \IfStrEq{#1}{A}{
            \setcounter{rank}{1}
        }{
        \IfStrEq{#1}{B}{
            \setcounter{rank}{2}
        }{
        \IfStrEq{#1}{C}{
            \setcounter{rank}{3}
        }{}}}
        \ifnum \value{page}=\value{thispage}\else
            \setcounter{thispage}{\value{page}}
            \setcounter{pagerank}{\value{rank}}
        \fi
        \ifnum \value{rank}>\value{pagerank}
            \setcounter{pagerank}{\value{rank}}
        \fi     
        \ifnum \value{pagerank}=1
            \def\pageclass{Alpha}
        \else \ifnum \value{pagerank}=2
            \def\pageclass{Beta}
        \else \ifnum \value{pagerank}=3
            \def\pageclass{Charlie}
        \fi \fi \fi
        \fancyhead[C]{\bfseries{\Large \pageclass}}
        \fancyfoot[C]{\thepage \\ \bfseries{\Large \pageclass}}
        (#1)
    }
\makeatother

\begin{document}
    \setlength{\headheight}{1in}
    \fancyhf{}
    \setClass{A}Lorem Ipsum Dolor Sit Alum\\
    \setClass{B}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{A}
    \Blindtext[1]
    \setClass{B}
    \Blindtext[1]
    \setClass{C}
    \Blindtext[1]
\end{document}
share|improve this answer
    
I don't think that your code is reliable due to the asynchronous page builder. –  Ulrike Fischer Feb 12 '13 at 20:15
    
That was one of my worries when starting this. Sorry for the poor description but I forgot to mention that it was meant to block paragraphs and so on. (A) applies to the entire paragraph and so on. If the (B) paragraph goes onto the next page then that page is (B) as well. I basically moved the series of IfStrEq after the page checker statement. –  Eric Feb 12 '13 at 21:34
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.