TeX - LaTeX Asked on February 18, 2021
I use the KOMA script scrlttr2
and just want to display the same text (my page numbering/number) on all pages of my letter, of course including the first one.
I’ve found this answer and this somewhat old blog post.
But both are awkwardly complicated and require me to define a heck of LaTex macros for just doing the same it automatically does beginning with page two (2).
How can I display the same text (page number) on the first page’s footer as in the footer on the second/al other pages?
In contrast to all other questions I’m not searching for the most elegant solution (that takes 100 lines), but I’d be fine with duplicating/hardcoding the footer again by repeating it. Even if it would take me to write “Page 1 of letterlastpage”.
I basically use this example, taken from here:
documentclass{scrlttr2}
usepackage{scrlayer-scrpage}
cfoot{Page thepage of letterlastpage}
usepackage{lipsum}
begin{document}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
end{document}
The layout of the first letter page is special. The page style of the first letter page is empty
. It uses special elements for the address, location, header, footer etc.
You have to use variable firstfoot
to add content in the footer of the first page. If you redefine pagemark
to get »Page ... of ...«, then you can use centeringpagemark
for firstfoot
:
renewcommand*pagemark{%
usekomafont{pagenumber}{pagename~thepage~of~letterlastpage}%
}
setkomavar{firstfoot}{centeringpagemark}
Example:
documentclass{scrlttr2}
renewcommand*pagemark{%
usekomafont{pagenumber}{pagename~thepage~of~letterlastpage}%
}
setkomavar{firstfoot}{centeringpagemark}
usepackage{lipsum}
begin{document}
begin{letter}{Jerry Garcia710 Ashbury StSan FranciscoCA 94117}
opening{Dear Friend,}
lipsumlipsum
end{letter}
begin{letter}{Jerry Garcia710 Ashbury StSan FranciscoCA 94117}
opening{Dear Friend,}
lipsumlipsum
end{letter}
end{document}
Note that the footer on the fist page is lower than on the other pages. If it should be at the same position, then you can patch opening
to use page style plain
on the first page:
newcommand{originalopening}{}
letoriginalopeningopening
renewcommand{opening}[1]{originalopening{#1}thispagestyle{plain}}
KOMAoptions{firstfoot=false}% disable first footer
or with package xpatch
:
usepackage{xpatch}
xpatchcmd{opening}{thispagestyle{empty}}{thispagestyle{plain}}{}{PatchFailed}
KOMAoptions{firstfoot=false}% disable first footer
Note that you can still use variable firsthead
to define a header of the first letter page.
Example:
documentclass{scrlttr2}
renewcommand*pagemark{%
usekomafont{pagenumber}{pagename~thepage~of~letterlastpage}%
}
usepackage{xpatch}
xpatchcmd{opening}{thispagestyle{empty}}{thispagestyle{plain}}{}{PatchFailed}
KOMAoptions{firstfoot=false}% disable first footer
usepackage{lipsum}
begin{document}
begin{letter}{Jerry Garcia710 Ashbury StSan FranciscoCA 94117}
opening{Dear Friend,}
lipsumlipsum
end{letter}
begin{letter}{Jerry Garcia710 Ashbury StSan FranciscoCA 94117}
opening{Dear Friend,}
lipsumlipsum
end{letter}
end{document}
Correct answer by esdd on February 18, 2021
The footer on the first page of a letter is empty by default.
You will need to define your own first-page footer using the firstfoot
variable and set its position from the top of the page with the firstfootvpos
variable.
Switch the footer on with the firstfoot=true
option.
The subsequent footers (done with cfoot
from the scrlayer-scrpage
package in your code example; it works OK) can also be set within scrlttr2
by using its nextfoot
variable.
Also, since there is no letterhead in the example, and no reference, I've taken the liberty of moving the to-address and the letter body further up the page a bit, to use some of the space.
MWE
documentclass[firstfoot=true,
enlargefirstpage=true,
firsthead=false,
]{scrlttr2}
%%usepackage{scrlayer-scrpage}
%cfoot{Page thepage of letterlastpage}
setplength{toaddrvpos}{footskip}
setplength{refvpos}{3.5footskip}
pagestyle{myheadings}
%markboth{}{}
setplength{firstfootvpos}{pageheight-1.5footskip}setkomavar{firstfoot}{%
parbox[t]{linewidth}{%
centering textit{Page thepage of letterlastpage}%
}%
}
setkomavar{nextfoot}{%
parbox[t]{linewidth}{%
centering textit{Page thepage of letterlastpage}%
}%
}
usepackage{lipsum}
begin{document}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
end{document}
Answered by Cicada on February 18, 2021
By combining multiple answers (linked in the code), I've found a solution that just uses the internal scrlttr2
parameter, i.e. mostly pagemark
.
Also you have one place to define the page number style there.
documentclass[enlargefirstpage=true]{scrlttr2}
usepackage{scrlayer-scrpage}
% better page numbers with total number
% https://tex.stackexchange.com/a/578072/98645
renewcommand*pagemark{%
usekomafont{pagenumber}{pagename~thepage~of~letterlastpage}%
%usekomafont{pagenumber}{-~thepage~von~letterlastpage~-}% different style example
}
% also show page number on first page
% https://tex.stackexchange.com/a/578050/98645
markboth{}{}
setkomavar{firstfoot}{%
parbox[t]{linewidth}{%
centering pagemark%
}%
}
usepackage{lipsum}
begin{document}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
begin{letter}{%
Jerry Garcia
710 Ashbury St
San Francisco
CA 94117
}
opening{Dear Friend,}
lipsumlipsum
end{letter}
end{document}
Answered by rugk on February 18, 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