[Tex/LaTex] Aligning address with body of letter in scrlttr2

horizontal alignmentkoma-scriptscrlttr2

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}

Best Answer

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.)