TeX - LaTeX Asked by FancyDocsNewbie on January 29, 2021
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.
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}
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]
{parxdeflegalpagestyle{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}
Answered by esdd on January 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP