5

I have a long backaddress and want it to be displayed correctly in the addressee box. I have searched a lot and don't know, if there is a DIN for this too. I am wondering if noone else has ever had the problem of a long backaddress, but I haven't found anything about it.

My problem: I have a long backaddress to display. If I use the (default) KOMA option backaddress=underlined, the backaddress runs out of the addressee box. If I use backaddress=plain it seems to work. However I would like a line between backaddress and toaddress similar to the first option.

backaddress=plain:

<code>backaddress=plain</code> does work (?)

backaddress=underlined:

<code>backaddress=underlined</code> does not work (?)

Source:

\documentclass[
foldmarks=off,
backaddress=plain, % plain/underlined (problem with long address)
%fromrule=below, % not the line I am looking for
parskip=half, % paragraph formatting
draft
]{scrlttr2}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Fontencoding: 7bit -> 8bit
\usepackage{lmodern}
\usepackage{graphicx} % for \scalebox
\usepackage{microtype} % adjust text better
\usepackage{blindtext} % blindtext for MWE

% make signature left-aligned
\makeatletter
\renewcommand*{\raggedsignature}{\raggedright}
\makeatother

% change pagenumbering "Page X" -> "-X-"
\renewcommand\pagemark{\usekomafont{pagenumber}--\ \thepage\ --}

% change pagestyle of first page % http://tex.stackexchange.com/questions/298966/pagestyle-of-koma-letter-package
\usepackage{xpatch}
\xapptocmd{\opening}{\thispagestyle{headings}}{}{}

% use a small bullet as separator in the addressee for backaddress
\setkomavar{backaddressseparator}{~{$\vcenter{\hbox{\scalebox{0.5}{$\bullet$}}}$} }

% adjust some spacings
\makeatletter
% spacing between \closing and signature
\setlength{\@tempskipa}{-1\baselineskip}%
\@addtoplength{sigbeforevskip}{\@tempskipa}

% spacing between top border and firstheader
\setlength{\@tempskipa}{\baselineskip}%
\@addtoplength{firstheadvpos}{\@tempskipa}

% MWE: increase size of backaddress field in addressee (window of envelope) to make it fit there
\setlength{\@tempskipa}{2\baselineskip}%
\@addtoplength{backaddrheight}{\@tempskipa}

% alignment of header and addressee %http://tex.stackexchange.com/questions/64690/aligning-address-with-body-of-letter-in-scrlttr2
\@setplength{toaddrhpos}{\dimexpr 1in +\oddsidemargin\relax}
\@setplength{toaddrwidth}{8cm}
\@setplength{toaddrindent}{0cm}
\@setplength{firstheadhpos}{\dimexpr 1in +\oddsidemargin\relax}
\@setplength{firstheadwidth}{\textwidth}
\makeatother

\LoadLetterOption{visualize}% loads visualize.lco to visualize boxes
\showfields{address}% show the address box




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\setkomavar{fromname}{A long, long name for backaddress}
\setkomavar{fromaddress}{And of course the address\\
    which is quite long too\\
    last line}
\setkomavar{signature}{Another long name for the signature}

\setkomavar{place}{Home}

\setkomavar{subject}{Very important subject for the MWE}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{letter}{%
    toaddressname\\
    toaddress1\\
    toaddress2}

\opening{Dear xy,}

\blindtext

\vspace{2\baselineskip}
\closing{\hspace{3em}Kind regards,}


\end{letter}

\end{document}

So my idea was to edit the addressee field, which is included in the \opening macro.

The definition in scrlttr2.cls:

\newcommand{\opening}[1]{%
    \@PapersizeWarning
    \@gen@firsthead
    \@mkboth{\scr@fromname@var}{\scr@subject@var}%
    \thispagestyle{empty}\noindent
    \@foldmarks\@firstheadfootfield\@addrfield\@locfield
    \ifdim\useplength{subjectvpos}=\z@\else\@subjfield\fi
    \@datefield
    \@makelettertitle
    \ifdim\useplength{subjectvpos}=\z@\if@subjafter\else\@subjfield\fi\fi
    {\setparsizes{\z@}{\z@}{\z@ plus 1fil}\par@updaterelative#1\par}%
    {\setlength{\@tempdima}{\baselineskip}%
        \addtolength{\@tempdima}{-\parskip}%
        \ifdim \@tempdima>\z@\vskip\@tempdima\fi}%
    \ifdim\useplength{subjectvpos}=\z@\if@subjafter\@subjfield\fi\fi
    \@afterindentfalse\@afterheading
}

For the addressee field one has to look at \@addrfield. This definition is way longer and looks complicated to me. I am not sure how to investigate further. Is it useful to go this way? I am currently "reverse engineering" using \renewcommand. Any better suggestions?

I have a feeling that the \baselineskip in the backaddress isn't reduced even though it's footnotesize. Is this correct (typographically)? How to change it?

Thank you for your help and merry christmas ;)

nox
  • 4,160
  • 12
  • 26

1 Answers1

6

There is not only a KOMA-Script option backaddress for the switch between underlined and plain but also a KOMA-Script variable backaddress. Normally it uses the contents of the variables fromname and fromaddresse. You could change its contents and use a shorter version of the address aa backaddress.

\setkomavar{backaddress}{short from name\\short from address}

Result:

enter image description here

If you really want to use a multiline backoddress you have to note that default value underline for option backaddress uses command \underline. This command does not allow a linebreak in its argument. So you have to use something like a \parbox to insert an underlined multiline backaddress.

You could package varwidth (the backaddress could be shorter than the width of the addressfield) and change the KOMA-Script variable backaddress to

% use varwidth for the backaddress
\makeatletter
\setkomavar{backaddress}{%
    \begin{varwidth}{\useplength{toaddrwidth}}
        {\def\\{\usekomavar{backaddressseparator}\@ogobble}%
        \usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}}
    \end{varwidth}%
}
\makeatother

enter image description here

Code:

\documentclass[
    foldmarks=off,
    %backaddress=plain, % plain/underlined (problem with long address)
    %fromrule=below, % not the line I am looking for
    parskip=half, % paragraph formatting
    %draft
]{scrlttr2}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc} % Inputencoding
\usepackage[T1]{fontenc} % Fontencoding: 7bit -> 8bit
\usepackage{lmodern}
\usepackage{graphicx} % for \scalebox
\usepackage{microtype} % adjust text better
\usepackage{blindtext} % blindtext for MWE

\usepackage{varwidth}% <- added

% make signature left-aligned
\renewcommand*{\raggedsignature}{\raggedright}
% change pagenumbering "Page X" -> "-X-"
\renewcommand\pagemark{\usekomafont{pagenumber}--\ \thepage\ --}
% change pagestyle of first page % http://tex.stackexchange.com/questions/298966/pagestyle-of-koma-letter-package
\usepackage{xpatch}
\xapptocmd{\opening}{\thispagestyle{headings}}{}{}

% use a small bullet as separator in the addressee for backaddress
\setkomavar{backaddressseparator}{~{$\vcenter{\hbox{\scalebox{0.5}{$\bullet$}}}$} }
% use varwidth for the backaddress
\makeatletter
\setkomavar{backaddress}{%
    \begin{varwidth}{\useplength{toaddrwidth}}
        {\def\\{\usekomavar{backaddressseparator}\@ogobble}%
        \usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}}
    \end{varwidth}%
}
\makeatother

% adjust some spacings
\makeatletter
% spacing between \closing and signature
\@addtoplength{sigbeforevskip}{-\baselineskip}
% spacing between top border and firstheader
\@addtoplength{firstheadvpos}{\baselineskip}
% MWE: increase size of backaddress field in addressee (window of envelope) to make it fit there
\@addtoplength{backaddrheight}{2\baselineskip}

% alignment of header and addressee %http://tex.stackexchange.com/questions/64690/aligning-address-with-body-of-letter-in-scrlttr2
\@setplength{toaddrhpos}{\dimexpr 1in +\oddsidemargin\relax}
\@setplength{toaddrwidth}{8cm}
\@setplength{toaddrindent}{0cm}
\@setplength{firstheadhpos}{\dimexpr 1in +\oddsidemargin\relax}
\@setplength{firstheadwidth}{\textwidth}
\makeatother

\LoadLetterOption{visualize}% loads visualize.lco to visualize boxes
\showfields{address}% show the address box

\begin{document}
\setkomavar{fromname}{A long, long name for backaddress}
\setkomavar{fromaddress}{%
    And of course the address\\
    which is quite long too\\
    last line%
}
\setkomavar{signature}{Another long name for the signature}
\setkomavar{place}{Home}
\setkomavar{subject}{Very important subject for the MWE}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{letter}{%
    toaddressname\\
    toaddress1\\
    toaddress2}

\opening{Dear xy,}
\blindtext
\vspace{2\baselineskip}
\closing{\hspace{3em}Kind regards,}
\end{letter}
\end{document}
esdd
  • 85,675
  • Ah, I think I get the trick: You use a varwidth box instead of the text itself. Then this is displayed and afterwards the default underlined option takes effect - that's why there is this line. Correct so far? I didn't know, that backaddress is displayed in this case, just thought of it as as switch. I assume this works, because it is redefined depending on the passed argument (e.g. plain)? What's the difference between these two backaddresses? – nox Dec 25 '16 at 23:54
  • There is a difference between the KOMA-Script option backaddress and the KOMA-Script variable `backaddress*. See my updated answer. – esdd Dec 26 '16 at 07:08
  • Wow, great work! I wasn't aware of this. Thank you :) – nox Dec 26 '16 at 17:10