scrlttr2
似乎不喜欢长度超过一行的“反向地址”。默认布局的两行反向地址在“地址窗口”顶部突出,并且基线距离非常大。
我想找到一个配置,涵盖由 和 构建的单行和双行反向地址fromname
,fromaddress
因为布局是在 LCO 文件中定义的,该文件由不同的人使用。为了保持处理简单,定义单独的较短反向地址也不是一种选择。处理双行反向地址的一种方法似乎是。这种方法有点管用(请参阅下面的 MWE)。但我无法使用和parbox
获得良好的单词间距和正确的连字符。parbox
raggedright
因此,我正在寻找一个具有正确连字符、单词间距以及可能的话左对齐的解决方案。
我尽力而为的 MWE:
\documentclass[backaddress=plain]{scrlttr2}
\usepackage[main=ngerman]{babel}
\usepackage{blindtext}
% visualize border of address window
\LoadLetterOption{visualize}
\showfields{address}
\setkomafont{field}{\color{blue}}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Mittelhochdeutsche Allgemeine Versuchsanstalt\\Musterstr. 12\\34567 Musterstadt}
% construct a new backaddress
\makeatletter
\@setplength{backaddrheight}{18pt}
\setkomavar{backaddress}{\parbox[c]{\useplength{toaddrwidth}}{%
{%\raggedright% <- (1) has no effect
\def\\{\usekomavar{backaddressseparator}\@ogobble}%
%\raggedright% <- (2) breaks replacment of \\ with separator
\usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}}%
\raggedright% <- (3) prevents hyphenation but is left aligned
}}
\makeatother
\begin{document}
\begin{letter}{Dr. Moritz Busch\\Georgengarten\\30167 Hannover}
\opening{Mein lieber Freund,}
\blindtext[1]
\closing{Bis bald,}
\end{letter}
\end{document}
raggedright
位置 3 的MWE 图像:
答案1
要获得正确的连字符和左对齐文本,只需使用包ragged2e
和命令\RaggedRight
(请注意两个大写的 R)。
使用以下 MWE
\documentclass[backaddress=plain]{scrlttr2}
\usepackage[main=ngerman]{babel}
\usepackage{blindtext}
\usepackage{ragged2e} % <===============================================
% visualize border of address window
\LoadLetterOption{visualize}
\showfields{address}
\setkomafont{field}{\color{blue}}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Mittelhochdeutsche Allgemeine Versuchsanstalt\\Musterstr. 12\\34567 Musterstadt}
% construct a new backaddress
\makeatletter
\@setplength{backaddrheight}{18pt}
\setkomavar{backaddress}{\parbox[c]{\useplength{toaddrwidth}}{%
{%\raggedright% <- (1) has no effect
\def\\{\usekomavar{backaddressseparator}\@ogobble}%
%\raggedright% <- (2) breaks replacment of \\ with separator
\usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}}%
\RaggedRight% <- (3) prevents hyphenation but is left aligned <================
}}
\makeatother
\begin{document}
\begin{letter}{Dr. Moritz Busch\\Georgengarten\\30167 Hannover}
\opening{Mein lieber Freund,}
\blindtext[1]
\closing{Bis bald,}
\end{letter}
\end{document}
你得到了想要的结果:
答案2
我将重新定义backaddressseparator
以允许在之后休息,
:
\setkomavar{backaddressseparator}{,\ }
然后你可以使用
\documentclass[backaddress=plain]{scrlttr2}
\usepackage[main=ngerman]{babel}
\usepackage{blindtext}
% visualize border of address window
\LoadLetterOption{visualize}
\showfields{address}
\setkomafont{field}{\color{blue}}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Mittelhochdeutsche Allgemeine Versuchsanstalt\\Musterstr. 12\\34567 Musterstadt}
% construct a new backaddress
\setplength{backaddrheight}{18pt}%
\setkomavar{backaddressseparator}{,\ }
\setkomavar{backaddress}{%
{\usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}\par}%
}
\begin{document}
\begin{letter}{Dr. Moritz Busch\\Georgengarten\\30167 Hannover}
\opening{Mein lieber Freund,}
\blindtext[1]
\closing{Bis bald,}
\end{letter}
\end{document}
或者
\documentclass[backaddress=plain]{scrlttr2}
\usepackage[main=ngerman]{babel}
\usepackage{blindtext}
% visualize border of address window
\LoadLetterOption{visualize}
\showfields{address}
\setkomafont{field}{\color{blue}}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Mittelhochdeutsche Allgemeine Versuchsanstalt\\Musterstr. 12\\34567 Musterstadt}
% construct a new backaddress
\setplength{backaddrheight}{18pt}
\setkomavar{backaddressseparator}{,\ }
\makeatletter
\setkomavar{backaddress}{\parbox[c]{\useplength{toaddrwidth}}{%
\def\\{\usekomavar{backaddressseparator}\@ogobble}%
\usekomavar{fromname}\usekomavar{backaddressseparator}\usekomavar{fromaddress}}%
}
\makeatother
\begin{document}
\begin{letter}{Dr. Moritz Busch\\Georgengarten\\30167 Hannover}
\opening{Mein lieber Freund,}
\blindtext[1]
\closing{Bis bald,}
\end{letter}
\end{document}
但我会定义一个新变量shortfromaddress
:
\documentclass[backaddress=plain]{scrlttr2}
%\providecommand*{\Ifkomavarempty}{\ifkomavarempty}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage[main=ngerman]{babel}
\usepackage{blindtext}
% visualize border of address window
\LoadLetterOption{visualize}
\showfields{address}
\setkomafont{field}{\color{blue}}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Mittelhochdeutsche Allgemeine Versuchsanstalt\\Musterstr. 12\\34567 Musterstadt}
% construct a new backaddress
\newkomavar{shortfromaddress}
\setkomavar{backaddress}{%
\usekomavar{fromname}\usekomavar{backaddressseparator}
\Ifkomavarempty{shortfromaddress}%
{\usekomavar{fromaddress}}
{\usekomavar{shortfromaddress}}%
}
\setkomavar{shortfromaddress}{MAV\\Musterstr. 12\\34567 Musterstadt}
\begin{document}
\begin{letter}{Dr. Moritz Busch\\Georgengarten\\30167 Hannover}
\opening{Mein lieber Freund,}
\blindtext[1]
\closing{Bis bald,}
\end{letter}
\end{document}