1

I've been playing with the scrlttr2 class. See example script below. I'm having some trouble with vertical positioning.

I've got a line at the top of my LaTeX files which add some version control accounting information to the output. See Embedding Mercurial version control information in a TeX document for the details.

For the purpose of this exercise, I just stuck in a string. I have a couple of questions.

  1. It is possible to customize the extended letterhead in scrlttr2? I thought it should be possible to add that accounting information as part of the letterhead using the custom variable firsthead. But I was unable to find any actual examples of the use of firsthead. The problem with my current setup is that placing that line using eso-pic overlaps the letterhead, so I have to move the letterhead down. I do this using firstheadvpos, but it would be better not to have to do that.

  2. Also, moving the letterhead down starts to run into the toaddress. How can I adjust the space between the letterhead and the toaddress? I would have expected the letterhead and the toaddress to automatically keep some relative space between each other, but that doesn't seem to happen.

Here is the code.

\documentclass[12pt,foldmarks=true,foldmarks=blmtP,fromalign=center,
fromphone,fromemail,version=last, backaddress=false]{scrlttr2}
\usepackage{eso-pic,picture}
\AddToShipoutPictureBG*{
  \AtPageUpperLeft{
    \put(\oddsidemargin+1in+0.5\textwidth,-1.5cm){%
      \makebox[0pt][c]{\textbf{ex.tex}
      c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530}}
  }
}

\usepackage{fouriernc}
\begin{document}
\setkomavar{fromname}{Someone Else}
\setkomavar{fromaddress}{Some Other Bldg.\\ Some Road\\ Some City}
\setkomavar{fromphone}{22019466}
\setkomavar{fromemail}{faheem@faheem.info}
%\setkomavar{firsthead}[foo]{}
\makeatletter\@setplength{firstheadvpos}{1.7cm}\makeatother

\def\today{13th March, 2015}
\begin{letter}{
    \vspace{0.5cm}
    Someone\\ Some Org\\ Some Place\\ Some Road\\ Some City\\
    Subject: Some subject}

  \opening{Someone,}

\closing{Yours Sincerely,}

\end{letter}
\end{document}
  • You can adjust the spaces, but remember that by default, the rules of the german DIN are used, specifying where on the page the receiver of the letter has to be. That ensures, that the little envelopes with the window work. – Johannes_B Mar 15 '15 at 18:32
2

AFAIK there is no way to add this information at the top of the default first head. Using the option fromalign=Center and the variable firsthead you can define your own header.

Maybe you are looking for something like that

\setkomavar{firsthead}{%
  \parbox{\linewidth}{\centering
    \textbf{ex.tex}c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530\\
    \usekomavar{fromname}\\
    \usekomavar{fromaddress}\\
    \usekomavar*{fromphone}\usekomavar{fromphone}\\
    \usekomavar*{fromemail}\usekomavar{fromemail}
  }%
}

There is no relative space between firsthead and toaddress. The vertical position of toaddress is determined by the pseudolength toaddrvpos absolutely. But there should be a minimum distance, so you get a warning that your first head is too high. That means the first head is too close to the address field.

The space for the first head can be enlarged using

\makeatletter
% enlarge the first head by 5pt to avoid the warning
\@addtoplength[-]{firstheadvpos}{5pt}
\makeatother

Then -5pt will be added to the pseudolength firstheadvpos So the distance between the upper edge of the paper and the upper edge of the first head is decreased by 5pt. That means the margin above of the first head gets 5pt smaller.

Another possibility is adding 5pt to toaddrvpos by

\makeatletter
% enlarge the first head by 5pt to avoid the warning
\@addtoplength{toaddrvpos}{5pt}
\makeatother

So the address field moves 5pt down and is no longer at the best place for a german window envelope.

The pseudolengths and the related commands are explained in the KOMA-Script documentation, chapter »Additional Information about the Letter Class scrlttr2 and the Letter Package scrletter«. There is also a figure showing the pseudolengths.

enter image description here

Code:

\documentclass[12pt,foldmarks=true,foldmarks=blmtP,fromalign=center,
fromphone,fromemail,version=last, backaddress=false,
subject=titled% <- added 
]{scrlttr2}

\usepackage{fouriernc}

\setkomavar{fromname}{Someone Else}
\setkomavar{fromaddress}{Some Other Bldg.\\ Some Road\\ Some City}
\setkomavar{fromphone}{22019466}
\setkomavar{fromemail}{faheem@faheem.info}
\setkomavar{subject}{Some subject}% <-added

\setkomavar{firsthead}{%
  \parbox{\linewidth}{\centering
    \textbf{ex.tex}c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530\\
    \usekomavar{fromname}\\
    \usekomavar{fromaddress}\\
    \usekomavar*{phoneseparator}\usekomavar{phoneseparator}\usekomavar{fromphone}\\
    \usekomavar*{emailseparator}\usekomavar{emailseparator}\usekomavar{fromemail}
  }%
}

\makeatletter
% enlarge the first head by 5pt to avoid the warning
\@addtoplength[-]{firstheadvpos}{5pt}
\makeatother

\def\today{13th March, 2015}
\begin{document}
\begin{letter}{Someone\\ Some Org\\ Some Place\\ Some Road\\ Some City}
\opening{Someone,}
\closing{Yours Sincerely,}
\end{letter}
\end{document}

Of course you can customize the firsthead and firstfoot. As an example

\makeatletter
\@addtoplength{firstheadvpos}{5pt}
\makeatother

\setkomavar{firsthead}{%
  \begin{tabular}[b]{l@{}}%
    \usekomavar{fromname}\\
    \usekomavar*{fromphone}\usekomavar{fromphone}\\
    \usekomavar*{fromemail}\usekomavar{fromemail}
  \end{tabular}
  \hfill
  \normalsize
  \begin{tabular}[b]{r@{}}%
    \usekomavar{fromaddress}
  \end{tabular}\\
  \rule[2mm]{\textwidth}{0.5pt}%
}

\setkomavar{firstfoot}{%
  \parbox{\linewidth}{\centering\textbf{ex.tex}
    c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530}\\[.5\baselineskip]
}

enter image description here


But may be you only want to add the information above the first head without changing the letter layout. Then you can load the package scrlayer and add a layer to the pagestyle empty

\usepackage{scrlayer}
\DeclareNewLayer[
  background,head,align=b,voffset=\useplength{firstheadvpos},height=\baselineskip,
  contents={\makebox[\layerwidth]{\textbf{ex.tex}
    c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530}}
  ]{versioncontrol.head}
\AddLayersToPageStyle{empty}{versioncontrol.head}

enter image description here

Code:

\documentclass[12pt,foldmarks=true,foldmarks=blmtP,fromalign=center,
fromphone,fromemail,version=last, backaddress=false,
subject=titled,% <- added 
]{scrlttr2}

\usepackage{fouriernc}

\setkomavar{fromname}{Someone Else}
\setkomavar{fromaddress}{Some Other Bldg.\\ Some Road\\ Some City}
\setkomavar{fromphone}{22019466}
\setkomavar{fromemail}{faheem@faheem.info}
\setkomavar{subject}{Some subject}% <-added

\usepackage{scrlayer}
\DeclareNewLayer[
  background,head,align=b,voffset=\useplength{firstheadvpos},height=\baselineskip,
  contents={\makebox[\layerwidth]{\textbf{ex.tex}
    c1cf35eef2c30d69fd2c41171434f4f1acd32c0d 2015-03-15 20:17 +0530}}
  ]{versioncontrol.head}
\AddLayersToPageStyle{empty}{versioncontrol.head}

\def\today{13th March, 2015}
\begin{document}
\begin{letter}{Someone\\ Some Org\\ Some Place\\ Some Road\\ Some City}
\opening{Someone,}
\closing{Yours Sincerely,}
\end{letter}
\end{document}
  • Thanks for your answer. I'll take a look at it tomorrow. It would be nice if KOMA had some kind of clean override of the default letterhead contents. Specifically, there doesn't seem to be a variable that contains the default value of the letterhead. One has to construct it manually, as you did. – Faheem Mitha Mar 15 '15 at 20:12
  • Does \@addtoplength[-]{firstheadvpos}{5pt} just add 5pt to the value of firstheadvpos? Can you add a reference for this macro? – Faheem Mitha Mar 15 '15 at 20:17
  • See my edited answer. – esdd Mar 16 '15 at 8:20
  • Thank you for the very detailed reply. I'll take a look at it soon. – Faheem Mitha Mar 16 '15 at 9:01
  • I have updated my answer. firstheadvpos and toaddrvpos are the vertical distances from the top edge of the paper. If I need more space for the first head I have to decrease the firstheadvpos or/and to increase the toaddrvpos. – esdd Mar 17 '15 at 1:09

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.