Ich verwende die Klasse scrlttr2
KOMA-Script mit einem benutzerdefinierten Seitenlayout über das geometry
Paket. Leider führt dies zu einer kleinen horizontalen Rechtsverschiebung meines Headers. Hier ist ein 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}
und ein Screenshot des Ergebnisses:
Wie kann ich die schwarze Linie mit dem untenstehenden Text in Einklang bringen?
Antwort1
Nun, in Ihrem Code gibt es zwei Probleme und eine fehlende Längendefinition:
\firsthead
Verwenden Sie stattdessen den Befehl\setkomavar{firsthead}{
(ich bin sicher, Sie haben diesbezüglich eine Warnung erhalten!?), da der Befehl veraltet ist.- Sie müssen
@{}
am Anfang Ihrer Tabelle Folgendes hinzufügen,\begin{tabular}{ll@{}}
um den Text genau am rechten Ende der Zeile zu erhalten. - Sie müssen hinzufügen
\@setplength{firstheadhpos}{16mm}
, da Sieleft=16mm
in verwendet haben\geometry
.
Also mit dem vollständigen Code:
\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}
Sie erhalten das Ergebnis:
Antwort2
Standardmäßig firstheadhpos
ist die Pseudolänge auf eingestellt \maxdimen
. Dies führt zu einer horizontal zentrierten Kopfzeile. Ihr Textbereich ist jedoch nicht horizontal zentriert. Sie müssen die Pseudolänge daher firstheadhpos
auf denselben Wert wie Ihren linken Rand einstellen.
\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}
Ergebnis:
Beachten Sie, dass ich die nicht damit zusammenhängenden Dinge entfernt und einige Änderungen vorgenommen habe, um die aktuelle Syntax für die firsthead
Variable zu verwenden. Mit einer aktuellen KOMA-Script-Version (aktuell ist 3.26) können Sie \setplength
stattdessen verwenden \@setplength
.