如何将信件文档类中的发件人地址位置移至左侧

如何将信件文档类中的发件人地址位置移至左侧

这个更多地涉及垂直空间,而不是水平空间: 在信函中定位地址

我知道scrlttr2文档类,但是该类letter具有更好的默认格式(我只需要更改一个参数),而scrlttr2产生的文档在美观上令人不快,在发件人的信息中输出冗余,并且需要大量的工作才能使其看起来像letter我发现几乎完美的类: 带有地址字段的 LaTeX 信件位于“带窗口的 C5 信封”的正确位置

我愿意使用这个scrlttr2类,但我找不到一个模板让它看起来更好看letter。这是一个:

scrlttr2:收件人地址的位置

但如果可能的话,我宁愿对这个letter课程做一些小小的修复。

以下是我目前所拥有的 .tex 文件:

\documentclass{letter}
\usepackage{hyperref}
\usepackage[english=nohyphenation]{hyphsubst}
\usepackage{tabularx}
\usepackage[left=2.0cm, right=3.0cm, top=3cm, bottom=2cm, bindingoffset=0cm, showframe=false]{geometry}
\renewcommand{\tabcolsep}{15cm}
\newcommand{\subject}[1]{% This macro will need one argument
  {\begin{center} \bfseries \underline{#1} \end{center}}% Centred and bold text
}
\signature{Shafique Jamal}
\address{Shafique Jamal \\ 31 Streetname Drive \\ Town, Province \\ Canada ZIP POS}
\longindentation=0pt
\begin{document}
\begin{letter}{\TeX Stack Exchange Group \\ Office \\ 23 Streets Name \\ Town, Country POSTAL }
\opening{Dear Fellow Stack People:}
\subject{Subject: Subject goes here}

Can you help me move the sender's address to the left? It is too close to the right edge. I would like to make sure that it does not go more to the right than does the text in the body of the letter.

\closing{Sincerely,}
\end{letter}
\end{document}

结果是这样的:

LaTeX 输出的屏幕截图

发件人的地址太靠右了 - 我想将其移到更靠左的位置,这样发件人的地址文本就不会比信件正文中的文本更靠右了。有什么建议吗?

答案1

我不知道这句话的用意

\renewcommand{\tabcolsep}{15cm}

在您的代码中使用。这是问题的根源。注释掉这个就可以治愈疾病。

另一方面,如果您与\tabcolsepof有关系15cm(看起来很奇怪),请将其添加到您的序言中。

\makeatletter
\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\raggedleft\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\raggedleft\begin{tabular}{@{}l@{}}\ignorespaces  %% earlier it was \begin{tabular}{l@{}}
      \fromaddress \\*[2\parskip]%
      \@date \end{tabular}\par}%
  \fi
  \vspace{2\parskip}% 
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\makeatother

或者etoolbox

\usepackage{etoolbox}

\patchcmd{\opening}{\begin{tabular}{l@{}}}    %% search
                    {\begin{tabular}{@{}l@{}}} %% replace
                    {}{}

完整代码:

\documentclass{letter}
\usepackage{hyperref}
\usepackage[english=nohyphenation]{hyphsubst}
\usepackage{tabularx}
\usepackage[left=2.0cm, right=3.0cm, top=3cm, bottom=2cm, bindingoffset=0cm, showframe]{geometry}
\renewcommand{\tabcolsep}{15cm}
\newcommand{\subject}[1]{% This macro will need one argument
  {\begin{center} \bfseries \underline{#1} \end{center}}% Centred and bold text
}
\signature{Shafique Jamal}
\address{Shafique Jamal \\ 31 Streetname Drive \\ Town, Province \\ Canada ZIP POS}
\longindentation=0pt

\usepackage{etoolbox}
\patchcmd{\opening}{\begin{tabular}{l@{}}}    %% search
                    {\begin{tabular}{@{}l@{}}} %% replace
                    {}{}


%\makeatletter
%\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
%  \thispagestyle{firstpage}%
%    {\raggedleft\@date\par}%
%  \else  % home address
%    \thispagestyle{empty}%
%    {\hspace*{\fill}\begin{tabular}{@{}l@{}}\ignorespaces
%      \fromaddress \\*[2\parskip]%
%      \@date \end{tabular}\par}%
%  \fi
%  \vspace{2\parskip}% 
%  {\raggedright \toname \\ \toaddress \par}%
%  \vspace{2\parskip}%
%  #1\par\nobreak}
%\makeatother

\begin{document}
\begin{letter}{\TeX Stack Exchange Group \\ Office \\ 23 Streets Name \\ Town, Country POSTAL }
\opening{Dear Fellow Stack People:}
\subject{Subject: Subject goes here}

Can you help me move the sender's address to the left? It is too close to the right edge. I would like to make sure that it does not go more to the right than does the text in the body of the letter.

\closing{Sincerely,}
\end{letter}
\end{document}

在此处输入图片描述

答案2

我一直觉得该类letter在组成方面非常受限且困难。以非常灵活的方式重新创建布局非常简单:

在此处输入图片描述

\documentclass{article}
\usepackage[left=2.0cm, right=3.0cm, top=3cm, bottom=2cm, bindingoffset=0cm, showframe=false]{geometry}
\newcommand{\subject}[1]{% This macro will need one argument
  {\begin{center} \bfseries \underline{#1} \end{center}}% Centred and bold text
}
\setlength{\parindent}{0pt}
\begin{document}

\vspace*{3cm}

\hfill
\begin{tabular}{l@{}}
  Shafique Jamal \\
  31 Streetname Drive \\
  Town, Province \\
  Canada ZIP POS \\ \\
  \today
\end{tabular}

\bigskip

\begin{tabular}{@{}l}
  \TeX Stack Exchange Group \\
  Office \\
  23 Streets Name \\
  Town, Country POSTAL
\end{tabular}

\bigskip

Dear Fellow Stack People:

\subject{Subject: Subject goes here}

Can you help me move the sender's address to the left? 
It is too close to the right edge. I would like to make 
sure that it does not go more to the right than does the 
text in the body of the letter.

\bigskip

Sincerely,

\vspace{4\baselineskip}

Shafique Jamal

\end{document}

相关内容