4

I am using class scrlttr2 of KOMA-Script with a custom page layout via the geometry package. Unfortunately, this results in a small horizontal right-shift of my header. Here is a 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}

and a screenshot of the result:

resulting screenshot

How can I make the black rule in align with the text below?

  • Instead of using the geometry package with the scrlttr2 class I suggest to use \areaset{17cm}{24cm} which approximately set the margins you need – Hafid Boukhoulda Feb 24 at 6:18
6

Well, in your code are two issues and a missing length definition:

  1. Instead command \firsthead use \setkomavar{firsthead}{ (I'm sure you got a warning about that!?), because the command is depreciated.
  2. You need to add @{} to your begin of the table: \begin{tabular}{ll@{}} to get the text exact on the right end of line.
  3. You need to add \@setplength{firstheadhpos}{16mm} because you used left=16mm in \geometry.

So with the complete 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}

you get the result:

enter image description here

  • Beautiful, thanks! Just to point out, the lack of a newline after \setkomavar{firsthead}{ (i.e., the % sign) is also important to get the text flush left. – Felix Feb 24 at 18:03
3

By default the pseudo length firstheadhpos is set to \maxdimen. This results in a header horizontal centered to the paper. But your text area is not horizonal centered to the page. So you have to set the pseudo length firstheadhpos to the same value as your left margin.

\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}

Result:

screen shot of the result

Note, that I have removed the unrelated stuff and added some changes to use the uptodate syntax for the firsthead variable. With an uptodate KOMA-Script version (current is 3.26) you can use \setplength instead \@setplength.

  • Thanks for the great answer! Now I just need to wait for KOMA 3.26 to become available in ubuntu. – Felix Feb 24 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.