Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In scrlttr2, I wish to align the address with the body of the letter. I tried this:

\@setplength{toaddrhpos}{\oddsidemargin}

But it moves the address almost to the left edge of the paper.

How can I achieve the alignment that I desire?

Example:

h.lco

\ProvidesFile{h.lco}[2012/07/25]

\@setplength{toaddrhpos}{\oddsidemargin}

\endinput

letter.tex

\documentclass[h]{scrlttr2}

\usepackage[english]{babel}


\begin{document}

\begin{letter}{Name\\Address\\City}


\opening{Dear Madam or Sir:}

Hello.

\closing{Very truly yours,}


\end{letter}
\end{document}
share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Markus Kohm, the author if KOMAscript, has included a nowindow-lco in the samples to his book (see Beispiele aus der 4. Auflage des KOMA-Script-Buches). The sources for the file is:

% nowindow.lco
% Copyright 2008 Markus Kohm
% 
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% 
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Markus Kohm.
% 
% This work consists of this file only.
%-----------------------------------------------------------------------
\ProvidesFile{nowindow.lco}%
  [2003/01/24 v0.1 unsupported letter-class-option]
\@setplength{firstheadwidth}{\textwidth}
\@setplength{toaddrhpos}{\oddsidemargin}
\@addtoplength{toaddrhpos}{1in}
\KOMAoptions{backaddress=false}
\endinput

Copy this source to a text editor and save it as nowindow.lco in your tex search path (your texmf-local), or to the same directory as your letter. Remember to update the tex file database (run texhash or whatever command on your system, for example ‘Refresh FNDB’ from the Settings in MiKTeX.)

A MWE for the use of nowindow.lco:

\documentclass[UKenglish]{scrlttr2}
\usepackage{babel}
\usepackage[utf8]{inputenx}
\LoadLetterOption{nowindow}

\begin{document}
\begin{letter}{Name of Recipient \\ Address \\ of \\ Recipient}

\opening{Hello}  % eg. Hello

\closing{Kind regards} %eg. Regards

\end{letter}
\end{document}

EDIT: PSH asks why you have to add 1in to the \toaddrhpos. This is explained by Markus Kohn in this reply at Komascript’s home page. An approximate translation from German:

In the end the 1in originate from the history of TeX. TeX does not start in the outer margin of the page, but move one inch to the left and one inch down. Consequently, the \oddsidemargin is one inch less than the margin on the even side pages. To make it easier for the user, the pseudo-lenght is calculated from the real left margin (and from the real top of the page). Therefore, you have to take that one inch into consideration when you are using \oddsidemargin in an pseudo-lenght.

(German natives, feel free to improve the translation.)

share|improve this answer
    
Thank you, but I do not understand why it should be necessary to add 1in. –  PSH Jul 25 '12 at 22:18
    
This is because TeX by design start the left margin one inch (25.4 mm) from the outer margin and one inch (25.4 mm) from the top margin. You have to compensate for that. You will find the explanation at www.komascript.de if you read German. –  Sveinung Jul 26 '12 at 6:39
    
Thank you again. Yes, I do read German. I'll have a look at Kohn's explanation. –  PSH Jul 26 '12 at 13:20
add comment

This answer elaborates on Sveinung's.

At \opening, scrlttr2 "moves into position" to print the "to address" using \move@topl which is defined as:

\newcommand*{\move@topl}{%
  \null\hskip -1in%
  \ifodd\value{page}\hskip -\oddsidemargin\else\hskip -\evensidemargin\fi
  \ignorespaces%
}

followed by an \hskip of size "\toaddrhpos". So, setting "\toaddrhpos" to be the same as the distance skipped by \move@topl (in the opposite direction), voids any horizontal movement. As such, adding

\makeatletter
\@setplength{toaddrhpos}{\dimexpr\oddsidemargin+1in}
\makeatother

should suffice, since the opening usually is on an odd page.

share|improve this answer
    
Thank you both. That does indeed solve the problem. I don't like the hard-coded value of 1in, but I'll use it for want of a cleaner solution. –  PSH Jul 26 '12 at 2:51
    
@PSH: The 1in length is hard-coded in the actual document class file scrlttr2.cls. That was the author's choice, so there's no way around it. –  Werner Jul 26 '12 at 6:39
    
@Werner The 1in is hard coded in the TeX engine. –  Sveinung Jul 26 '12 at 7:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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