Nice question; I solved it by changing \addrentry
and adding something innocuous to \begin{letter}
, that will do nothing if a subsequent \makeopening
command doesn't follow.
In the usual \addentry
command, the last argument is used to build a control sequence that stores the address lines. I add also the building of an opening line, which for MEIER
is stored in \opening@MEIER
. This command is called by \makeopening
(using the hook added before).
\documentclass[
paper=a4,
version=last,
enlargefirstpage,
fontsize=11pt]{scrlttr2}
\usepackage[english,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{xpatch}
%%% Patch the relevant scrlttr macros
\makeatletter
% at the end of \begin{letter}{<name>} store the <name>
\xapptocmd\letter{\gdef\this@letter@to{#2}}{}{}
% this seems complicated, but is needed to strip off
% the backslash from the argument to `\begin{letter}`
% Don't use `\makeopening` if the argument to `\begin{letter}`
% is not obtained via the `.adr` file
% we need to get \opening@MEIER from the fact that
% \this@letter@to expands to \MEIER so we first expand
% \this@letter@to, then \string, so that \@gobble will
% remove the backslash
\newcommand\makeopening{%
\@nameuse{%
opening@%
\expandafter\expandafter\expandafter
\@gobble\expandafter\string\this@letter@to}}
% modify \addrentry to define an opening and
% the address lines as desired
\newif\if@company
\renewcommand\addrentry[9]{%
\def\@tempa{#1}%
\ifx\@tempa\@empty
\else
\@companyfalse
\if#5m%
\@namedef{opening@#9}{\opening{Dear Mr.\ #1,}}%
\else
\if#5w%
\@namedef{opening@#9}{\opening{Dear Mrs.\ #1,}}%
\else
\@namedef{opening@#9}{\opening{Sirs,}}%
\@companytrue
\fi
\fi
\def\@tempa{#2}%
\ifx\@tempa\@empty
\if@company
\@namedef{#9}{#1\\#6\\#3}%
\else
\@namedef{#9}{#1\\#3}%
\fi
\else
\if@company
\@namedef{#9}{#2\\#6\\#3}%
\else
\@namedef{#9}{#2 #1\\#3}%
\fi
\fi
\fi
}
\makeatother
% global koma vars
\setkomavar{fromname}{Max Myname}
\setkomavar{fromphone}{+49\,123\,45678910}
\setkomavar{fromemail}{mymail@gmail.com}
\setkomavar{backaddress}{Max Myname, Some Street 12, 012345 Somewhere}
\setkomavar{fromaddress}{Some Street 12\\012345 Somewhere}
\begin{document}
\setkomavar{subject}{The subject}
\setkomavar{date}{\today}
\setkomavar{place}{Dresden}
\setkomavar{yourmail}{1.1.2013}
\setkomavar{yourref}{76/54/321}
\setkomavar{myref}{123/456/789}
\input{meier.adr}
\begin{letter}{\MEIER}
\makeopening
\lipsum[7]
\closing{Sincerely yours}
\end{letter}
\begin{letter}{\CCI}
\makeopening
\lipsum[7]
\closing{Sincerely yours}
\end{letter}
\end{document}
Here are the two letters (relevant parts only)
Is there anyway I can make it look like the letterstyle? I am just
going through this to add a subject line, so if there's a simpler way
it would be equally good.
It sounds like what you really want is to be able to add a subject line to the standard letter
class, and that you really do not want to use scrlttr2
. If that is the case you can just modify the letter
class \opening
macro. I use the etoolbox
\patchcmd
, but I am sure there are other ways. The key part is
\makeatletter
\newcommand{\subject}[1]{\def\@subject{#1}}
\patchcmd{\opening}{#1\par\nobreak}{\ifundef{\@subject}{}{\textbf{\@subject}\par\vspace{2\parskip}}#1\par\nobreak}{}{}
\makeatother
You would then specify the subject with \subject
, just like you specify \name
. A full MWE is
\documentclass{letter}
\usepackage{etoolbox}
\makeatletter
\newcommand{\subject}[1]{\def\@subject{#1}}
\patchcmd{\opening}{#1\par\nobreak}{\ifundef{\@subject}{}{\@subject\par\vspace{2\parskip}}#1\par\nobreak}{}{}
\makeatother
\name{My name}
\signature{My signature}
\address{My road\\My city}
\location{My location}
\telephone{my telephone}
\subject{My subject}
\begin{document}
\begin{letter}{To name\\To road\\To city}
\opening{Dear \toname}
Hello World
\end{letter}
\end{document}
Best Answer
The horizontal position of the the address field is determined by the pseudolength
toaddrhpos
. A value oftoaddrhpos
greater than 0 means the distance from the left border, a value lower than 0 means the distance from the right border.So you could use something like
or
Code:
Other pseudolengths related to the address field are
toaddrvpos
,toaddrwidth
andtoaddrheight
.And you can use
\addtokomafont{addressee}{\raggedleft}
to right align the address in the address field:Code:
But there are also some Letter Class Option files included in the KOMA-Script Distribution having the recipient's address on the right.
Use
\LoadLetterOption{SN}
(Swiss letters with address field on the right side) in the preambel to get:Or
\LoadLetterOption{NF}
(French letters):