KOMA scrlttr2 - 反向地址太长,编辑收件人;间距/行

KOMA scrlttr2 - 反向地址太长,编辑收件人;间距/行

我有一个很长的地址backaddress,希望它能在框中正确显示addressee。我搜索了很多,但不知道是否也有 DIN。我想知道是否没有人遇到过长地址反向问题,但我没有找到任何相关信息。

我的问题:我要显示很长的反向地址。如果我使用(默认)KOMA 选项backaddress=underlined,反向地址会超出收件人框。如果我使用backaddress=plain它,它似乎有效。但是我希望反向地址和收件人地址之间有一条类似于第一个选项的线。

backaddress=plain

<code>backaddress=plain</code> 有效(?)

backaddress=underlined

<code>backaddress=underlined</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

% 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}

所以我的想法是编辑addressee包含在\opening宏中的字段。

中的定义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
}

对于收件人字段,必须查看\@addrfield。这个定义对我来说太长了,看起来很复杂。我不确定如何进一步调查。这样做有用吗?我目前正在使用进行“逆向工程” \renewcommand。有什么更好的建议吗?

我感觉\baselineskipbackaddress 中的 并没有减少,尽管它是footnotesize。这是否正确(印刷上)?如何更改它?

谢谢您的帮助,祝您圣诞快乐;)

答案1

不仅有一个用于在和backaddress之间切换的KOMA-Script 选项,还有一个 KOMA-Script 变量。通常它使用变量和的内容。您可以更改其内容并使用地址 aa backaddress 的较短版本。underlinedplainbackaddressfromnamefromaddresse

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

结果:

在此处输入图片描述

如果您确实想使用多行反向地址,则必须注意underline选项的默认值backaddress使用命令\underline。此命令不允许在其参数中换行。因此,您必须使用类似的东西\parbox来插入带下划线的多行反向地址。

您可以打包varwidth(反向地址可能短于地址字段的宽度)并将 KOMA-Script 变量更改backaddress

% 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

在此处输入图片描述

代码:

\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}

相关内容