1

I have very recently discovered Latex while trying to write consistently edited monthly technical reports for my customer.

Problem: how to make the footer change to a predetermined text based on the content of the page, especially when the content occupies partial and not whole pages.

More details: There are three different legal statements that I have to choose from, depending on the material on the page/pages to stick in the footer.

So far I have tried: fancyhdr package and created four pagestyles. To start off I set the global header footer. This works just as expected, all pages get the same header and footer. For material that needs one of the three legal statements I use thispagestyle and pick one of the custom defined page styles to change the footer through a pagestyle. As you can already guess, when the content is say, 1.5 pages long, I get the desired footer on the first page where the paragraph appears, then it reverts to the global footer on the next page.

Desired behavior would be let the second page also have this footer, and change back only on the third page.

I am using documentclass article. No specific reason to pick it, other than copy pasta from the internet. Not knowledgeable enough to pick the correct one.


Edit 2020-11-05: Sample Code to recreate the problem:

\documentclass[12pt, letterpaper]{article}
\usepackage{graphicx}
\usepackage{geometry}
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\usepackage{lipsum, blindtext}
\usepackage[T1]{fontenc}


%%% HEADERS & FOOTERS
\usepackage{fancyhdr}

%\pagestyle{fancy}

%
\fancypagestyle{nolegal}
{
    \pagestyle{fancy}
    \fancyfoot[L]{}
    \fancyfoot[C]{}
    \fancyfoot[R]{\thepage}
    %\footskip=30pt
}

\fancypagestyle{legal1}
{
    \pagestyle{fancy}
    \fancyfoot[L]{}
    \fancyfoot[C]{legal 1 Applies to Content}
    \fancyfoot[R]{\thepage}
    \footskip=30pt
}
\pagestyle{nolegal}

\begin{document}
    \textbf{(No special legal applies)}\\
    \lipsum[1-6]
    
    \textbf{(Begin legal 1)}\\
    \thispagestyle{legal1} % Also tried \pagestyle{legal1} [Line 40]
    \lipsum[1-6]
    \newline
    \textbf{(End legal 1)}
    
    % If switching page style in line 40, switch back with \pagestyle{nolegal}
    \lipsum[1-3]
    
\end{document}

As expected page 2 generated by this sample gets the statement in the footer correctly. However, it gets removed on page 3.

4
  • Welcome to TeX.se. Can you create a small sample document with dummy text that shows the what you've done and how it doesn't work and edit your question to add it. You can use the lipsum package to generate dummy text.
    – Alan Munn
    Commented Nov 3, 2020 at 1:33
  • you should use \pagestyle if you want to change the page style for more than one page. Commented Nov 3, 2020 at 8:05
  • Hi Ulrike, it has the same result. I "sandwich" the paragraphs between two 'pagestyle' statements, and TeX does not hold the special footer on the second page.
    – SkyAdd
    Commented Nov 4, 2020 at 18:29
  • Alan Munn, will do ASAP.
    – SkyAdd
    Commented Nov 4, 2020 at 18:30

1 Answer 1

1

You have to use \pagestyle at the beginning of a statement and \thispagestyle at its end. Then you can switch back to the default page style using \pagestyle.

\documentclass[12pt, letterpaper]{article}
\usepackage[headheight=14.5pt,footskip=30pt]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}

\usepackage{fancyhdr}
%\pagestyle{fancy}

\fancypagestyle{nolegal}
{
    \pagestyle{fancy}
    \fancyfoot{}
    \fancyfoot[R]{\thepage}
}

\fancypagestyle{legal1}
{
    \pagestyle{fancy}
    \fancyfoot{}
    \fancyfoot[C]{legal 1 Applies to Content}
    \fancyfoot[R]{\thepage}
}
\pagestyle{nolegal}

\begin{document}
\textbf{(No special legal applies)}\\
\lipsum[1-6]

\textbf{(Begin legal 1)}\pagestyle{legal1}\\
\lipsum[1-6]
\newline
\textbf{(End legal 1)}\thispagestyle{legal1}

\pagestyle{nolegal}
\lipsum[1-3]
\end{document}

enter image description here

Maybe you can define a new environment:

\documentclass[12pt, letterpaper]{article}
\usepackage[headheight=14.5pt,footskip=30pt]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}

\usepackage{fancyhdr}
\pagestyle{fancy}

\fancypagestyle{nolegal}
{
    \fancyfoot{}
    \fancyfoot[R]{\thepage}
}
\fancypagestyle{legal1}
{
    \fancyfoot{}
    \fancyfoot[C]{legal 1 Applies to Content}
    \fancyfoot[R]{\thepage}
}
\pagestyle{nolegal}

\newcommand*\legalpagestyle{}
\newenvironment{legal}[1]
  {\par\xdef\legalpagestyle{legal#1}\pagestyle{\legalpagestyle}}
  {\thispagestyle{\legalpagestyle}\par}

\begin{document}
\textbf{(No special legal applies)}
\lipsum[1-6]

\begin{legal}{1}
\textbf{(Begin legal 1)}\\
\lipsum[1-10]
\newline
\textbf{(End legal 1)}
\end{legal}

\textbf{(No special legal applies)}
\lipsum[1-3]
\end{document}

enter image description here

1
  • The simplicity of solution 1 is mind-blowing. Thanks. IT WORKS! I will have to understand environments better and I might leverage solution 2 when time comes. Thanks a lot!
    – SkyAdd
    Commented Nov 12, 2020 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .