2

I created a letter featuring a header (with a logo at the right) and a footer holding some information. I would like to create a scrreprt document with the same header/footer layout. What's the easiest way to port? Especially, I want to use scrlttr2 komavars in the report, and also I'd like to have variables in one file only.

I'm grateful for any suggestion and for any direction-pointing on how to approach this!

This is the code for the letter:

\documentclass[
    fontsize=11pt,          % fontsize
    paper=a4,               % page size a4
    firsthead=on,           % display header on first page
    firstfoot=on,           % display footer on first page
    pagenumber=off,         % position of the page number
    parskip=half,           % Use indent instead of skip, half, false
    enlargefirstpage=on,    % more space on first page
    fromalign=left,         % placement of name in letter head
    fromrule=afteraddress,  % separate the address with a line in letter head, false or aftername
    fromemail=off,          % turn on email of sender
    fromurl=off,            % print URL of sender
    fromphone=off,          % turn on phone of sender
    fromlogo=off,           % turn on logo of sender
    addrfield=on,           % address field for envelope with window, on or true
    subject=titled,         % placement of subject, beforeopening or titled
    foldmarks=off,          % print foldmarks
    numericaldate=off,      % display date in numbers only
    KOMAold]{scrlttr2}

% http://mirrors.ctan.org/macros/latex/contrib/koma-script/doc/scrguien.pdf

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[dvips]{graphicx}
\usepackage[german]{babel}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{lastpage}
\usepackage[rgb]{xcolor}
\usepackage{hyperref}
\usepackage{varwidth}
\hypersetup{%
    pdfborder=0 0 0,
    pdfauthor={},
    pdftitle={},
    pdfsubject={},
    pdfkeywords={},
    pdfpagemode={UseOutlines},
    bookmarksopen,
    pdfstartview={FitH},
    colorlinks,
    linkcolor={blue},
    citecolor={red},
    urlcolor={blue}
  }

% Information in the header
\newcommand*{\headbox}{
  \usekomafont{pagenumber}
  \parbox[b]{\linewidth}{\noindent
  \hfill
  % \mbox{\includegraphics[draft,width=0.42\linewidth]{logo.png}} 
  \mbox{\rule{8cm}{2cm}}
  }
}

% Information in the footer
\newcommand*{\footbox}{
  \parbox[t]{\textwidth}{\sffamily\footnotesize
    \begin{tabular}[t]{@{}l@{}}%
      Mister Bean Club\\
      \usekomavar{chairmanname}\\
      \usekomavar{chairmanstreet}\\
      \usekomavar{chairmancity}
    \end{tabular}%
    \hfill
    \begin{tabular}[t]{@{}l@{}}%
      \usekomavar{fromphone}\\
      \usekomavar{fromfax}\\
      \usekomavar{fromemail}\\
      \usekomavar{fromurl}
    \end{tabular}%
    \hfill
    \begin{tabular}[t]{@{}l@{}}%
      \usekomavar{frombank}
    \end{tabular}
  }
}

\firsthead{\headbox}
\firstfoot{\footbox}

\setlength{\headsep}{4.5cm}
\setlength{\textheight}{8in}

\makeatletter
\@setplength{sigbeforevskip}{8ex} % 0ex space after the signature
\@setplength{toaddrwidth}{7cm}
\@addtoplength{firstheadvpos}{0mm} % 4.5mm position of header
\@addtoplength{firstfootvpos}{-8mm} % -8mm or -1ex position of footer
\makeatother

\newkomavar{fromstreet}
\newkomavar{fromcity}
\newkomavar{chairmanname}
\newkomavar{chairmanstreet}
\newkomavar{chairmancity}
\newkomavar{tostreet}
\newkomavar{tocity}

\setkomavar{date}[]{\today}
\setkomavar{place}{New York}

% scrlttr2: full sender information
\setkomavar{fromaddress}{\usekomavar{fromstreet}\\\usekomavar{fromcity}}

% chairman address information 
\setkomavar{chairmanname}{Mister Bean}
\setkomavar{chairmanstreet}{Main Street 42}
\setkomavar{chairmancity}{12345 New York}

\setkomavar{backaddress}{%
\begin{varwidth}{\useplength{toaddrwidth}}
    {%
      MBC \usekomavar{backaddressseparator}\usekomavar{fromname}\\
    \usekomavar{fromstreet}\usekomavar{backaddressseparator}\usekomavar{fromcity}}
\end{varwidth}%
}
\setkomavar{backaddressseparator}{~{$\vcenter{\hbox{\scalebox{0.5}{$\bullet$}}}$} }

% scrlttr2: align phone & fax numbers
\newlength{\fromphoneWidth}
\settowidth{\fromphoneWidth}{Telefon\enskip}
\setkomavar{fromphone}{\makebox[\fromphoneWidth][l]{Telefon}(0123) 456 78 90}
\setkomavar{fromfax}{\makebox[\fromphoneWidth][l]{Telefax}(0123) 456 78 90}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromurl}{www.misterbeanclub.com}
\setkomavar{frombank}{Bank New York\\
BIC / IBAN\enskip{}ABCDEFGH\\
US12 3456 7890 0000 0000 00\\
Tax-ref. 123/456/7890}

\setkomavar{toaddress}{\usekomavar{tostreet}\\
\vspace{\baselineskip} % cannot use \\ here
\usekomavar{tocity}
}

\setkomavar{fromname}{\usekomavar{chairmanname}}
\setkomavar{fromstreet}{\usekomavar{chairmanstreet}}
\setkomavar{fromcity}{\usekomavar{chairmancity}}

\setkomavar{subject}{title of the subject}
\setkomavar{signature}{Mister Bean}

\setkomavar{toname}{Receivers \& Co.}
\setkomavar{tostreet}{Vor dem Berg 1}
\setkomavar{tocity}{12345 Musterhausen}


\begin{document}

\begin{letter}{}
\vspace*{0ex} % Correct for vertical displacement

\opening{Dear Sir/Madam,}

\lipsum[3-4] 

\closing{Sincerely,}

\end{letter}
\end{document}

1 Answer 1

2

You can use package scrletter together with the KOMA-Script class scrreprt. Then you can define a new layer pagestyle using the pseudolength firstheadvpos and firstheadhpos and the variables firsthead and firstfoot.

\documentclass[
    fontsize=11pt,          % fontsize
    paper=a4,               % page size a4
    firsthead=on,           % display header on first page
    firstfoot=on,           % display footer on first page
    pagenumber=off,         % position of the page number
    parskip=half,           % Use indent instead of skip, half, false
    enlargefirstpage=on,    % more space on first page
    fromalign=left,         % placement of name in letter head
    fromrule=afteraddress,  % separate the address with a line in letter head, false or aftername
    fromemail=off,          % turn on email of sender
    fromurl=off,            % print URL of sender
    fromphone=off,          % turn on phone of sender
    fromlogo=off,           % turn on logo of sender
    addrfield=on,           % address field for envelope with window, on or true
    subject=titled,         % placement of subject, beforeopening or titled
    foldmarks=off,          % print foldmarks
    numericaldate=off,      % display date in numbers only
    usegeometry% <- added, needs KOMA-Script version 3.22 or newer
    ]{scrreprt}[2017/01/03]% <- changed
\usepackage{scrletter}% <- added
\LoadLetterOption{KOMAold}% must be loaded by \LoadLetterOption or \LoadLetterOptions
% http://mirrors.ctan.org/macros/latex/contrib/koma-script/doc/scrguien.pdf

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}% option dvips removed
\usepackage[german]{babel}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{lastpage}
\usepackage[rgb]{xcolor}
\usepackage{hyperref}
\usepackage{varwidth}
\hypersetup{%
    pdfborder=0 0 0,
    pdfauthor={},
    pdftitle={},
    pdfsubject={},
    pdfkeywords={},
    pdfpagemode={UseOutlines},
    bookmarksopen,
    pdfstartview={FitH},
    colorlinks,
    linkcolor={blue},
    citecolor={red},
    urlcolor={blue},
    hypertexnames=false% <- added
  }

% Information in the header
\newcommand*{\headbox}{% <- some spurious spaces removed in this macro
  \usekomafont{pagenumber}%
  \parbox[b]{\linewidth}{\noindent
    \hfill
  % \mbox{\includegraphics[draft,width=0.42\linewidth]{logo.png}} 
  \mbox{\rule{8cm}{2cm}}%
  }%
}

% Information in the footer
\newcommand*{\footbox}{% <- some spurious spaces removed in this macro
  \parbox[t]{\textwidth}{\sffamily\footnotesize
    \begin{tabular}[t]{@{}l@{}}%
      Mister Bean Club\\
      \usekomavar{chairmanname}\\
      \usekomavar{chairmanstreet}\\
      \usekomavar{chairmancity}
    \end{tabular}%
    \hfill
    \begin{tabular}[t]{@{}l@{}}%
      \usekomavar{fromphone}\\
      \usekomavar{fromfax}\\
      \usekomavar{fromemail}\\
      \usekomavar{fromurl}
    \end{tabular}%
    \hfill
    \begin{tabular}[t]{@{}l@{}}%
      \usekomavar{frombank}
    \end{tabular}%
  }%
}

\setkomavar{firsthead}{\headbox}% <- changed to new syntax
\setkomavar{firstfoot}{\footbox}% <- changed to new syntax

%%% new layers and new layer pagestyle
\DeclareNewLayer[
  background,
  textarea,
  voffset=\useplength{firstheadvpos}+1.5\baselineskip,
  mode=picture,
  contents=\putUL{\raisebox{-\height}{\usekomavar{firsthead}}}
]{likeletterfirstpage.head}
\DeclareNewLayer[
  foreground,
  textarea,
  voffset=\useplength{firstfootvpos}+1.5\baselineskip,
  mode=picture,
  contents=\putUL{\raisebox{\dimexpr-\height}{\usekomavar{firstfoot}}}
]{likeletterfirstpage.foot}

\DeclareNewPageStyleByLayers{likeletterfirstpage}{likeletterfirstpage.head,likeletterfirstpage.foot}
\pagestyle{likeletterfirstpage}
\renewcommand\chapterpagestyle{likeletterfirstpage}
%%%

\usepackage[top=4.5cm,textheight=8in]{geometry}% instead manual setting of headsep and textheight

\makeatletter
\@addtoplength{backaddrheight}{2.83pt}% <- added because of a warning
\@setplength{sigbeforevskip}{8ex} % 0ex space after the signature
\@setplength{toaddrwidth}{7cm}
\@addtoplength{firstheadvpos}{0mm} % 4.5mm position of header
\@addtoplength{firstfootvpos}{-8mm} % -8mm or -1ex position of footer
\makeatother

\newkomavar{fromstreet}
\newkomavar{fromcity}
\newkomavar{chairmanname}
\newkomavar{chairmanstreet}
\newkomavar{chairmancity}
\newkomavar{tostreet}
\newkomavar{tocity}

\setkomavar{date}[]{\today}
\setkomavar{place}{New York}

% scrlttr2: full sender information
\setkomavar{fromaddress}{\usekomavar{fromstreet}\\\usekomavar{fromcity}}

% chairman address information 
\setkomavar{chairmanname}{Mister Bean}
\setkomavar{chairmanstreet}{Main Street 42}
\setkomavar{chairmancity}{12345 New York}

\setkomavar{backaddress}{%
\begin{varwidth}{\useplength{toaddrwidth}}
    {%
      MBC \usekomavar{backaddressseparator}\usekomavar{fromname}\\
    \usekomavar{fromstreet}\usekomavar{backaddressseparator}\usekomavar{fromcity}}
\end{varwidth}%
}
\setkomavar{backaddressseparator}{~{$\vcenter{\hbox{\scalebox{0.5}{$\bullet$}}}$} }

% scrlttr2: align phone & fax numbers
\newlength{\fromphoneWidth}
\settowidth{\fromphoneWidth}{Telefon\enskip}
\setkomavar{fromphone}{\makebox[\fromphoneWidth][l]{Telefon}(0123) 456 78 90}
\setkomavar{fromfax}{\makebox[\fromphoneWidth][l]{Telefax}(0123) 456 78 90}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromurl}{www.misterbeanclub.com}
\setkomavar{frombank}{Bank New York\\
BIC / IBAN\enskip{}ABCDEFGH\\
US12 3456 7890 0000 0000 00\\
Tax-ref.\ 123/456/7890}

\setkomavar{toaddress}{\usekomavar{tostreet}\\
\vspace{\baselineskip} % cannot use \\ here
\usekomavar{tocity}
}

\setkomavar{fromname}{\usekomavar{chairmanname}}
\setkomavar{fromstreet}{\usekomavar{chairmanstreet}}
\setkomavar{fromcity}{\usekomavar{chairmancity}}

\setkomavar{subject}{title of the subject}
\setkomavar{signature}{Mister Bean}

\setkomavar{toname}{Receivers \& Co.}
\setkomavar{tostreet}{Vor dem Berg 1}
\setkomavar{tocity}{12345 Musterhausen}

\usepackage{blindtext}% for dummy text
\begin{document}
\blinddocument
\begin{letter}{}
\vspace*{0ex} % Correct for vertical displacement

\opening{Dear Sir/Madam,}

\lipsum[3-4]

\closing{Sincerely,}

\end{letter}
\end{document}

enter image description here

Note that there are some other changes. See the comments in the code. But maybe there are still other things in the code which should be changed. Unfortunaly I also did not know why there is an additional vertical shift of 1.5\baselineskip for the header and the footer.

0

You must log in to answer this question.

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