我正在通过包使用scrlttr2
带有自定义页面布局的 KOMA-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
嗯,您的代码中有两个问题和一个缺少的长度定义:
\firsthead
而是使用命令\setkomavar{firsthead}{
(我确信您收到了有关该命令的警告!?),因为该命令已被贬值。- 您需要
@{}
在表格的开头添加:\begin{tabular}{ll@{}}
以使文本精确地位于行的右端。 - 您需要添加,
\@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
。