使用 scrlttr2 从地址位置定义

使用 scrlttr2 从地址位置定义

如何使用 scrlttr2 模板定义 fromaddress 位置和大小?

对于接收者的地址,可以按如下方式进行

%These commands work
\@setplength{toaddrhpos}{1cm}
\@setplength{toaddrvpos}{1cm}
\@setplength{toaddrheight}{5cm}
\@setplength{toaddrwidth}{10cm}

但如果发件人的地址定义如下,

\setkomavar{fromaddress}{Road \\ Street \\ Town}

然后以下内容应该影响 fromaddress 位置

%These commands don't work
\@setplength{fromaddrhpos}{1cm}
\@setplength{fromaddrvpos}{1cm}
\@setplength{fromaddrheight}{5cm}
\@setplength{fromaddrwidth}{10cm}

遗憾的是,这些命令无法识别?fromaddress 位置必须以不同的方式定义吗?

以下是一封简单的例子

\documentclass[
    pagenumber=false, 
    parskip=half,
    fromalign=right,
    foldmarks=false, 
    addrfield=true, 
    backaddress=off
    ]{scrlttr2}

\usepackage[T1]{fontenc} % For extra glyphs (accents, etc)
\usepackage{stix} % Use the Stix font by default
\usepackage[english]{babel}

\renewcommand*{\raggedsignature}{\raggedright} % Stop the signature from indenting
\makeatletter
  \@setplength{toaddrhpos}{2.5cm}
  \@setplength{toaddrvpos}{0.5cm}
  \@setplength{toaddrheight}{3.5cm}
  \@setplength{toaddrwidth}{10cm} 
\makeatother


\setkomavar{fromname}{Joe Bloggs} % Your name used in the from address

\setkomavar{fromaddress}{Street \\ Town \\ City} % Your address

\setkomavar{signature}{Joe Bloggs} % Your name used in the signature

\date{\today} % Date of the letter

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

%----------------------------------------------------------------------------------------
%   ADDRESSEE
%----------------------------------------------------------------------------------------
 
\begin{letter}{Joe Blogg's Friend \\ Street \\ Town \\ City} 

%----------------------------------------------------------------------------------------
%   LETTER CONTENT
%----------------------------------------------------------------------------------------

\opening{Dear Joe Blogg's Friend,}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam aliquet tellus vel justo porta et semper libero rutrum. Duis vestibulum sagittis aliquam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac velit eu dolor lobortis fringilla. Quisque imperdiet porta ante in pretium. Maecenas facilisis varius metus et blandit. Proin rhoncus arcu non ante elementum non vehicula sem varius. Morbi feugiat, elit eget tristique posuere, urna eros vestibulum nibh, at tempus neque justo nec enim.

Curabitur id est enim. Suspendisse potenti. Fusce eleifend sodales tortor, a interdum tortor sollicitudin vel. Morbi vel tellus enim, eget hendrerit ligula. Proin molestie suscipit erat, eget consectetur orci convallis at. Ut vestibulum, odio vitae blandit dignissim, dui magna auctor leo, at molestie augue magna sed nisi. Phasellus ipsum magna, fringilla id tempor id, tristique vitae mauris. Maecenas sed orci vel eros consectetur ultrices.

Mauris enim velit, feugiat at venenatis eu, scelerisque vitae mauris. Nullam accumsan facilisis mauris sagittis iaculis. Mauris condimentum dictum libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nullam consequat malesuada feugiat. Vestibulum tempor commodo turpis id gravida.

\closing{Sincerely,}

\end{letter}
 
\end{document}

答案1

发送者的地址位于名为“location”的字段中。location 的伪长度定义如下:

 %These commands do work for location <==================================
\setplength{lochpos}{1cm}
\setplength{locvpos}{1cm}
\setplength{locheight}{5cm}
\setplength{locwidth}{10cm}

使用以下编译 TeX 代码(包括visualize显示位置字段和其他字段的选项...)

\documentclass[%
  pagenumber=false, 
  parskip=half,
  fromalign=locationright, % <==========================================
  foldmarks=false, 
  addrfield=true, 
  backaddress=off,
  visualize, % <========================================= to show fields
]{scrlttr2}

\usepackage[T1]{fontenc} % For extra glyphs (accents, etc)
\usepackage{stix} % Use the Stix font by default
\usepackage[english]{babel}

\renewcommand*{\raggedsignature}{\raggedright} % Stop the signature from indenting

\setplength{toaddrhpos}{2.5cm}
\setplength{toaddrvpos}{0.5cm}
\setplength{toaddrheight}{3.5cm}
\setplength{toaddrwidth}{10cm} 

\setkomavar{fromname}{Joe Bloggs} % Your name used in the from address
\setkomavar{fromaddress}{Street \\ Town \\ City} % Your address
\setkomavar{signature}{Joe Bloggs} % Your name used in the signature
\setkomavar{date}{\today} % Date of the letter <=========================

%These commands do work for location <==================================
\setplength{lochpos}{1cm}
\setplength{locvpos}{1cm}
\setplength{locheight}{5cm}
\setplength{locwidth}{10cm}
\showfields{head,address,location,refline,foot} % <======= for visualize

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

%----------------------------------------------------------------------------------------
%   ADDRESSEE
%----------------------------------------------------------------------------------------
 
\begin{letter}{Joe Blogg's Friend \\ Street \\ Town \\ City} 

%----------------------------------------------------------------------------------------
%   LETTER CONTENT
%----------------------------------------------------------------------------------------

\opening{Dear Joe Blogg's Friend,}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam aliquet 
tellus vel justo porta et semper libero rutrum. Duis vestibulum sagittis 
aliquam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Phasellus ac velit eu dolor lobortis fringilla. Quisque imperdiet porta 
ante in pretium. Maecenas facilisis varius metus et blandit. Proin 
rhoncus arcu non ante elementum non vehicula sem varius. Morbi feugiat, 
elit eget tristique posuere, urna eros vestibulum nibh, at tempus neque 
justo nec enim.

Curabitur id est enim. Suspendisse potenti. Fusce eleifend sodales tortor, a interdum tortor sollicitudin vel. Morbi vel tellus enim, eget hendrerit ligula. Proin molestie suscipit erat, eget consectetur orci convallis at. Ut vestibulum, odio vitae blandit dignissim, dui magna auctor leo, at molestie augue magna sed nisi. Phasellus ipsum magna, fringilla id tempor id, tristique vitae mauris. Maecenas sed orci vel eros consectetur ultrices.

Mauris enim velit, feugiat at venenatis eu, scelerisque vitae mauris. Nullam accumsan facilisis mauris sagittis iaculis. Mauris condimentum dictum libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nullam consequat malesuada feugiat. Vestibulum tempor commodo turpis id gravida.

\closing{Sincerely,}

\end{letter}
 
\end{document}

您将获得以下结果:

pdf 的结果部分

相关内容