scrlttr2 和幾何:firsthead 向右移動

scrlttr2 和幾何:firsthead 向右移動

我透過套件使用scrlttr2KOMA-Script 類別和自訂頁面佈局geometry。不幸的是,這導致我的標題出現輕微的水平右移。這是一個 MWE:

\documentclass
%---------------------------------------------------------------------------
  [fontsize=11pt,%%          Font size
%---------------------------------------------------------------------------
% Type area
   paper=a4,%%               Sheet size
   enlargefirstpage=on,%%    Enlarge the first page
   pagenumber=headright,%%   Page number on the top right of the header
%---------------------------------------------------------------------------
% Layout
   headsepline=on,%%         Line below the page number
   parskip=half,%%           Space between paragraphs
%---------------------------------------------------------------------------
% Letterhead and address
   fromalign=right,%%        Positioning of the letterhead
   fromphone=on,%%           Phone number in the sender's area
   fromrule=off,%%           Line below the sender's area (aftername, afteraddress)
   fromfax=off,%%            Fax number
   fromemail=off,%%          Mail address
   fromurl=off,%%            Homepage
   fromlogo=off,%%           Company logo
   addrfield=off,%%           Adress field for window envelopes
   backaddress=off,%%         ... with sender address
   subject=beforeopening,%%  Positioning of the subject
   locfield=narrow,%%        Additional field for the sender
   foldmarks=off,%%           Folding mark
   numericaldate=off,%%      Numerical date
   refline=narrow,%%         Spread of the reference line in the type area
   firstfoot=false,%
%---------------------------------------------------------------------------
% Formatting
   draft=false%%                Draft mode
]{scrlttr2}
%---------------------------------------------------------------------------


\usepackage{geometry}
\geometry{a4paper,left=16mm,right=20mm,bottom=25mm,top=23mm,marginparsep=0mm,marginparwidth=0mm,showframe}

%---------------------------------------------------------------------------
\begin{document}
%---------------------------------------------------------------------------
\makeatletter
\@setplength{sigbeforevskip}{0em} % space before signature, in case you write bigger than 12pt :-]
\@setplength{refvpos}{20mm}%\useplength{toaddrvpos}}
\@setplength{firstfootvpos}{285mm} % vertical footer position from top of page
\@setplength{firstheadwidth}{\textwidth}
\makeatother
%---------------------------------------------------------------------------


\setkomavar{signature}{Full name}

%---------------------------------------------------------------------------
\firsthead{
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\textbf{Name}\\
    Address
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\flushright
\begin{tabular}{ll}
Phone & xxx\\
Email & xxx
\end{tabular}

\end{minipage}
\rule{\textwidth}{2pt}
}

\setkomavar{date}{\today}
%---------------------------------------------------------------------------
\begin{letter}{}

\opening{Dear x:}


\closing{Sincerely,}

\end{letter}
\end{document}

以及結果的螢幕截圖:

結果截圖

如何使黑色規則與下面的文字對齊?

答案1

好吧,您的程式碼中有兩個問題和缺少長度定義:

  1. \firsthead相反,使用命令\setkomavar{firsthead}{(我確定您收到了有關此的警告!?),因為該命令已被棄用。
  2. 您需要@{}在表格的開頭添加:\begin{tabular}{ll@{}}以使文字準確地位於行的右端。
  3. 您需要添加,\@setplength{firstheadhpos}{16mm}因為您left=16mm在 中使用過\geometry

完整的程式碼如下:

\documentclass
%---------------------------------------------------------------------------
  [fontsize=11pt,%%          Font size
%---------------------------------------------------------------------------
% Type area
   paper=a4,%%               Sheet size
   enlargefirstpage=on,%%    Enlarge the first page
   pagenumber=headright,%%   Page number on the top right of the header
%---------------------------------------------------------------------------
% Layout
   headsepline=on,%%         Line below the page number
   parskip=half,%%           Space between paragraphs
%---------------------------------------------------------------------------
% Letterhead and address
   fromalign=right,%%        Positioning of the letterhead
   fromphone=on,%%           Phone number in the sender's area
   fromrule=off,%%           Line below the sender's area (aftername, afteraddress)
   fromfax=off,%%            Fax number
   fromemail=off,%%          Mail address
   fromurl=off,%%            Homepage
   fromlogo=off,%%           Company logo
   addrfield=off,%%           Adress field for window envelopes
   backaddress=off,%%         ... with sender address
   subject=beforeopening,%%  Positioning of the subject
   locfield=narrow,%%        Additional field for the sender
   foldmarks=off,%%           Folding mark
   numericaldate=off,%%      Numerical date
   refline=narrow,%%         Spread of the reference line in the type area
   firstfoot=false,%
%---------------------------------------------------------------------------
% Formatting
   draft=false%%                Draft mode
]{scrlttr2}
%---------------------------------------------------------------------------


\usepackage{geometry}
\geometry{a4paper,left=16mm,right=20mm,bottom=25mm,top=23mm,marginparsep=0mm,marginparwidth=0mm,showframe}


%---------------------------------------------------------------------------
\begin{document}
%---------------------------------------------------------------------------
\makeatletter
\@setplength{sigbeforevskip}{0em} % space before signature, in case you write bigger than 12pt :-]
\@setplength{refvpos}{20mm}%\useplength{toaddrvpos}}
\@setplength{firstfootvpos}{285mm} % vertical footer position from top of page
\@setplength{firstheadwidth}{\textwidth}
\@setplength{firstheadhpos}{16mm} % <===================================



\makeatother
%---------------------------------------------------------------------------


\setkomavar{signature}{Full name}

%---------------------------------------------------------------------------
\setkomavar{firsthead}{% <==============================================
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\textbf{Name}\\
    Address
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\flushright
\begin{tabular}{ll@{}} % <==============================================
Phone & xxx\\
Email & xxx
\end{tabular}

\end{minipage}
\rule{\textwidth}{2pt}%
}

\setkomavar{date}{\today}
%---------------------------------------------------------------------------
\begin{letter}{}

\opening{Dear x:}

\closing{Sincerely,}

\end{letter}
\end{document}

你得到結果:

在此輸入影像描述

答案2

預設情況下,偽長度firstheadhpos設定為\maxdimen。這會導致標題水平居中於紙張。但您的文字區域並未水平居中於頁面。因此,您必須將偽長度設定firstheadhpos為與左邊距相同的值。

\documentclass[
  fontsize=11pt,
  parskip=half,
  addrfield=off,
  firstfoot=false
]{scrlttr2}
\usepackage{geometry}
\newcommand*\myleftmargin{16mm}% <- added
\geometry{
  left=\myleftmargin,% <- changed
  right=20mm,bottom=25mm,top=23mm,marginparsep=0mm,marginparwidth=0mm,showframe}

\setplength{sigbeforevskip}{0em}
\setplength{refvpos}{20mm}
\setplength{firstfootvpos}{285mm}
\setplength{firstheadwidth}{\textwidth}

\setplength{firstheadhpos}{\myleftmargin}% <- added

%---------------------------------------------------------------------------
\begin{document}
\setkomavar{signature}{Full name}
\setkomavar{firsthead}{% <- remove spurious space and changed syntax
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\textbf{Name}\\
    Address
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\fontfamily{lmss}\selectfont\footnotesize
\renewcommand{\baselinestretch}{0.8}
\raggedleft
\begin{tabular}{ll@{}}% <- changed to align the last column with the rule
Phone & xxx\\
Email & xxx
\end{tabular}%
\end{minipage}
\par
\rule{\textwidth}{2pt}%
}

\begin{letter}{}
\opening{Dear x:}
\closing{Sincerely,}
\end{letter}
\end{document}

結果:

結果的螢幕截圖

請注意,我已經刪除了不相關的內容並添加了一些更改以使用firsthead變數的最新語法。使用最新的 KOMA-Script 版本(目前為 3.26),您可以\setplength使用\@setplength.

相關內容