Menu

HowTo_LetterLayer

How to use scrlayer-scrpage to output the same header and footer in the same position on all pages of a letter

Sometimes the same letterhead is to be used for letters on all sides. Thus, no distinction is made between first and second sheets. However, elements such as address and business line should of course still be output only on the first page.

It is true that there are solutions with corresponding typesetting settings and output of the variables firsthead within nexthead and firstfoot within nextfoot. In principle, however, it is also easy to define an appropriate page style directly with scrlayer-scrpage and use it on all pages.

The easiest way to do this is to use scrletter instead of scrlttr2 as letter class. scrletter is actually the class scrartcl with the package scrletter. In this case scrlayer-scrpage is already loaded anyway and a page style pair letter is defined. Here the main style outputs the contents of variables nexthead and nextfoot. To use letter instead of plain.letter on the following pages, you can either use \AtBeginLetter{\pagestyle{letter}} or directly use \renewcommand*{\letterpagestyle}{letter}.

For the first page of the letter, however, page style empty is hardcoded. Since scrlayer-scrpage is based on the scrlayer package, it is easy to define the page style empty as an alias of page style letter using \RedeclareLayerPagestyle{empty}{letter}. It is then no longer empty, of course. Alternatively you can use \AtBeginLetter{\thispagestyle{letter}}.

As a further measure, \setkomavar{firsthead}{} is then useful for the first page, so that the standard letterhead is not additionally output. However, one could still use the variable firsthead for contents that are to be additionally output on the first page only.

How the structure of letterhead and footer is actually chosen is not of importance in the final analysis. In the following example, it has turned out somewhat larger, which is why the calculated typesetting settings are modified via \AfterCalculatingTypearea to create the necessary room. Just as well one could realize suitable margin settings with the package geometry. In that case it would make sense to additionally specify option usegeometry when loading the class. More details can be found in the KOMA-Script manual.

For the demonstration of the principle procedure it should also not matter that the following example letter is in German.

\documentclass[ngerman]{scrletter}
\usepackage{babel}
\usepackage[svgnames]{xcolor}
\usepackage{mwe}

% Platz für einen größeren Kopf über die komplette Seitenbreite schaffen.
\AfterCalculatingTypearea{%
  \addtolength{\headheight}{\topmargin}%
  \addtolength{\headheight}{1in}%
  \setlength{\topmargin}{-1in}%
  \addtolength{\headheight}{2cm}%
  \addtolength{\textheight}{-2cm}%
}
\KOMAoptions{headwidth=\paperwidth,footwidth=\textwidth,footlines=2}
\recalctypearea

\setkomafont{pageheadfoot}{}% Kopf und Fuß im Standardfont

\setkomavar{nexthead}{%
  \smash{\includegraphics[width=.25\paperwidth,height=\headheight]{example-image}}%
  \hfill
  \smash{%
    \parbox[b][\headheight]{\dimexpr .75\paperwidth-1em}{\raggedright
      \color{DarkGoldenrod}%
      \usekomavar{fromname}\\
      \usekomavar{fromaddress}\\
      \color{MediumVioletRed}%
      \hspace*{-1em}\rule[1ex]{\dimexpr\hsize+2em}{1pt}\hspace*{-1em}\\
      \large\centering
      Wir graben die tiefsten Löcher und bauen die höchsten
      Burgen!\\[2ex]
    }%
  }%
}

\setkomafont{pagefoot}{\footnotesize}

\setkomavar{nextfoot}{%
  \textcolor{DarkGoldenrod}{Bank der spielenden Kinden}\\
  \textcolor{DarkGoldenrod}{IBAN DE12 3456 7890 1234 5678}\hfill\pagemark
}

\setkomavar{fromname}{Buddelberg und Enkel}
\setkomavar{fromaddress}{Sandelberg 4\\12345 Dünenhain}

\setkomavar{myref}{SND}
\setkomavar{yourref}{KID}
\setkomavar{customer}{1234-567}
\setkomavar{signature}{Sandy}
\setkomavar{subject}{Ihre Frage zu unserem Sandburgenbaukasten Feinkorn 7}

\setkomavar{firsthead}{}% Kein zusätzlicher Kopf auf der ersten Seite.

\RedeclarePageStyleAlias{empty}{letter}% Damit die erste Seite denselben
                                % Briefkopf hat
\renewcommand*{\letterpagestyle}{letter}% Anderenfalls ist plain.letter voreingestellt.

\begin{document}
\begin{letter}{Petra Spielkind\\Hinter dem Deich 8\\77777 Kiesreich}
  \opening{Hallo Petra,}
  \Blindtext[5]
  \closing{Schöne Grüße}
\end{letter}
\end{document}

Two pages of the example letter.


Related

Wiki (English): HowTo_Letter

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.