将页眉/页脚从 scrrtr2 移植到 scrreprt

将页眉/页脚从 scrrtr2 移植到 scrreprt

我创建了一封信,信中有页眉(右侧有徽标)和页脚,其中包含一些信息。我想创建一个scrreprt具有相同页眉/页脚布局的文档。最简单的移植方法是什么?特别是,我想在报告中使用scrlttr2 komavars,并且我希望只在一个文件中包含变量。

我非常感激任何关于如何解决这一问题的建议和指导!

这是该信件的代码:

\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

您可以将包scrletter与 KOMA-Script 类一起使用scrreprt。然后,您可以使用伪长度firstheadvposfirstheadhpos变量firsthead和定义新的图层页面样式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}

在此处输入图片描述

请注意,还有一些其他更改。请参阅代码中的注释。但也许代码中还有其他内容需要更改。不幸的是,我也不知道为什么1.5\baselineskip页眉和页脚有额外的垂直移位。

相关内容