scrlttr2:每页的页眉和页脚显示不正确

scrlttr2:每页的页眉和页脚显示不正确

我在用響鳴2写信(代码如下)。页眉和页脚在第一页上显示正确,但在第二页等页面上,布局不正确……即页眉乱码,页脚为斜体,且位置不正确。

有人能帮忙修改代码吗?谢谢

\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[dvips]{graphicx}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{lastpage}
\usepackage[rgb]{xcolor}
\usepackage{hyperref}
\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
\firsthead{\parbox[b]{\linewidth}{\noindent
    \fbox{
%        \includegraphics[width=0.1\linewidth]{logo.eps}
    }
  \hfill
    \fbox{
        \parbox[b]{0.5\linewidth}{\centering University \\ 123 Street, \\ City, State 12345}
    }
  \hfill
    \fbox{
%        \includegraphics[width=0.1\linewidth]{logo.eps}
    }
    }
    \vspace*{0.5ex}
%    \hrule\hrule
    \vspace*{0.5ex}
    \centering\scriptsize{Institute or Corporation}}

\nexthead{\parbox[b]{\linewidth}{\noindent
    \fbox{
%        \includegraphics[width=0.1\linewidth]{logo.eps}
    }
  \hfill
    \fbox{
        \parbox[b]{0.5\linewidth}{\centering University \\ 123 Street, \\ City, State 12345}
    }
  \hfill
    \fbox{
%        \includegraphics[width=0.1\linewidth]{logo.eps}
    }
    }
    \vspace*{0.5ex}
%    \hrule\hrule
    \vspace*{0.5ex}
    \centering\scriptsize{Institute or Corporation}}

% Information in the footer
\firstfoot{\parbox[b]{\linewidth}{\hrule\vspace*{0.5ex}\centering\scriptsize{name | organization | phone | email | web | copyright number: 12\,345\,678 \hfill \textcolor{blue}{\thepage}/\pageref{LastPage}}}}
\nextfoot{\parbox[b]{\linewidth}{\hrule\vspace*{0.5ex}\centering\scriptsize{name | organization | phone | email | web | copyright number: 12\,345\,678 \hfill \textcolor{blue}{\thepage}/\pageref{LastPage}}}}

% \removereffields % removes reference fields
% \makeatletter
% \@setplength{refvpos}{\useplength{toaddrvpos}}
% \makeatletter

\setkomavar{location}{\hspace{4em}\parbox[b]{\textwidth}{\today \\  Ref. No.}}
\setkomavar{customer}[]{Through proper channel}
\setkomavar{date}[]{} % Removes date

\makeatletter
\@setplength{sigbeforevskip}{8ex} % 0ex space after the signature
\makeatother

\makeatletter
\@addtoplength{firstheadvpos}{0mm} % 4.5mm position of header
\@addtoplength{firstfootvpos}{0mm} % -8mm or -1ex position of footer
\makeatother

\setkomavar{subject}{title of the subject}

% \setkomafont{title}{\normalfont\rmfamily\bfseries\Large} % changes the font of title
% \setkomavar{title}{\MakeUppercase{To whom it may concern}}

\begin{document}
\pagestyle{myheadings}

\setkomavar{fromname}{Your Name,\newline 123 Street, \newline City, State 12345 \\[0.5ex] Email: [email protected] \\ Phone: +00-123-456-7890} % Your name
\setkomavar{fromaddress}{123 Street, \\ City, State 12345}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromphone}{+00-123-456-7890}
\setkomavar{signature}{\usekomavar{fromname}}

\begin{letter}{Director, \\ Corporation, \\ 123 Street, \\ City, State 12345} % Addressee name and address
\vspace*{0ex} % Correct for vertical displacement
\opening{Dear Sir/Madam,}

\lipsum[3-8] % generates dummy text, scratch that and write the letter contents

\closing{Sincerely,}

\cc{Chancellor, 123 Street, City, State 12345}

\end{letter}
\end{document} 

答案1

使用 scrpage2 包代替 \nexthead 或 \nextfoot 来解决问题。

\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\ohead{\headbox}
\ofoot{\footbox}

可以使用以下命令调整头部高度;

\setlength{\headsep}{4.5cm}

当文本与页脚重叠时,使用以下命令调整文本高度;

\setlength{\textheight}{8in}

修改后的代码;

\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[dvips]{graphicx}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{lastpage}
\usepackage[rgb]{xcolor}
\usepackage{hyperref}
\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
  \fbox{
%    \includegraphics[width=0.12\linewidth]{logo.eps}
    }
  \hfill
  \fbox{
    \parbox[b]{0.5\linewidth}{\centering University \\ 123 Street, \\ City, State 12345}
    }
  \hfill
  \fbox{
%    \includegraphics[width=0.12\linewidth]{logo.eps}
   } 
}
  \newline
   \vspace*{1.5ex}
    \centering
   \scriptsize{Institute or Corporation}
}
\firsthead{\headbox}

% Information in the footer
\newcommand*{\footbox}{
\usekomafont{pagenumber}
\parbox[b]{\linewidth}{\hrule\vspace*{0.5ex}\centering\scriptsize{name | organization | phone | email | web | copyright number: 12\,345\,678 \hfill \textcolor{blue}{\thepage}/\pageref{LastPage}}}
}
\firstfoot{\footbox}

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

\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\ohead{\headbox}
\ofoot{\footbox}

% \removereffields % removes reference fields
% \makeatletter
% \@setplength{refvpos}{\useplength{toaddrvpos}}
% \makeatletter

\setkomavar{location}{\hspace{4em}\parbox[b]{\textwidth}{\today \\  Ref. No.}}
\setkomavar{customer}[]{Through proper channel}
\setkomavar{date}[]{} % Removes date

\makeatletter
\@setplength{sigbeforevskip}{8ex} % 0ex space after the signature
\makeatother

\makeatletter
\@addtoplength{firstheadvpos}{0mm} % 4.5mm position of header
\@addtoplength{firstfootvpos}{0mm} % -8mm or -1ex position of footer
\makeatother

\setkomavar{subject}{title of the subject}

% \setkomafont{title}{\normalfont\rmfamily\bfseries\Large} % changes the font of title
% \setkomavar{title}{\MakeUppercase{To whom it may concern}}

\begin{document}

\setkomavar{fromname}{Your Name,\newline 123 Street, \newline City, State 12345 \\[0.5ex] Email: [email protected] \\ Phone: +00-123-456-7890} % Your name
\setkomavar{fromaddress}{123 Street, \\ City, State 12345}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromphone}{+00-123-456-7890}
\setkomavar{signature}{\usekomavar{fromname}}

\begin{letter}{Director, \\ Corporation, \\ 123 Street, \\ City, State 12345} % Addressee name and address
\vspace*{0ex} % Correct for vertical displacement
\opening{Dear Sir/Madam,}

\lipsum[3-18] % generates dummy text, scratch that and write the letter contents

\closing{Sincerely,}

\cc{Chancellor, 123 Street, City, State 12345}

\end{letter}
\end{document}

答案2

只需添加选项

headheight=3cm,

添加到您的 scrlttr2 长选项列表中。

相关内容