Latex 字母:发件人地址左对齐

发布于 2024-08-12 21:58:16 字数 294 浏览 7 评论 0原文

这是我第一次使用 Latex 写信。我正在使用字母类。当我使用时:

\address{100 From Address \\ City, State \\ Pin}

发件人地址变为右对齐。有什么办法可以让它左对齐吗?我正在寻找的信件的格式是:发件人地址左对齐,然后是日期左对齐,然后是收件人地址左对齐,然后是开头和正文,最后是签名左对齐。

我设法使用以下方法使签名左对齐:\longindentation=0pt,其余项目已正确对齐 - 它只是右对齐的发件人地址。

This is my first time using Latex to write a letter. I am using the letter class. When I use:

\address{100 From Address \\ City, State \\ Pin}

The from address becomes right aligned. Is there someway I can make this left aligned. The format of the letter I am looking for is: the from address left aligned, followed by the date left aligned, followed by the to address left aligned, then opening and body, and finally signature left aligned.

I managed to get the signature left aligned by using: \longindentation=0pt, the rest of the items are properly aligned - its just the from address that is right aligned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜妞爱困 2024-08-19 21:58:16

答案是使用完整的大写字母样式 - 一切都左对齐。在 LaTeX 中,这是 block.sty,您可能需要安装它。您可以在这里找到它 http://www.ctan.org/tex-archive/macros/latex /contrib/block 。用法非常简单:

\usepackage{块}

The answer is to use the full block letter style - everything left-aligned. In LaTeX that is the block.sty, which you will probably have to install. You can find it here http://www.ctan.org/tex-archive/macros/latex/contrib/block . Usage is quite simple:

\usepackage{block}

就此别过 2024-08-19 21:58:16
\makeatletter
\def\opening#1{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\raggedleft\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\noindent\let\\\cr\halign{##\hfil\cr\ignorespaces
      \fromaddress \cr\noalign{\kern 2\parskip}%
      \@date\cr}\par}%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\makeatother
\makeatletter
\def\opening#1{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\raggedleft\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\noindent\let\\\cr\halign{##\hfil\cr\ignorespaces
      \fromaddress \cr\noalign{\kern 2\parskip}%
      \@date\cr}\par}%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\makeatother
汐鸠 2024-08-19 21:58:16

我假设“左对齐”意味着您希望地址块位于页面的左边距,因为该块的各个行是左对齐的,但该块位于右边距。

我发现调整 LaTeX 样式的最佳方法是找到定义原始样式的 LaTeX 源代码,将其复制到样式文件,然后进行修改。在本例中,原始源是 letter.cls 文件,我通过查找 \address 宏来跟踪地址格式,这导致了 \fromaddress 宏,然后是 \opening 宏。在原文中,它是:


\newcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\raggedleft\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\raggedleft\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}

删除 \raggedleft 宏将地址块移动到右侧,但留下一些额外的间距,因此我也删除了表格环境。


\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    \ignorespaces%
      \fromaddress \\*[2\parskip]%
      \@date \par%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}

此 \renewcommand 调用需要放入 .sty 样式文件中,因为它使用包含 @ 字符的宏。 (我刚刚看到 Alexey Malistov 的回答;另一个选择是 \makeatletter 和 \makeatother 宏。)用于


\usepackage{myletter}

引入新样式。

I assume by "left aligned" you mean that you want the address block to be on the left margin of the page, since the individual lines of the block are left aligned, but the block is at the right margin.

The best way I have found to adjust LaTeX styles is to locate in the LaTeX source where the original style is defined, copy it to a style file, and fiddle. In this case, the original source is the letter.cls file, and I tracked down the address formatting by looking for the \address macro, which led to the \fromaddress macro, and then to the \opening macro. In the original, it is:


\newcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\raggedleft\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\raggedleft\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}

Removing the \raggedleft macro moves the address block to the right side, but leaves some extra spacing, so I removed the tabular environment as well.


\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    \ignorespaces%
      \fromaddress \\*[2\parskip]%
      \@date \par%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}

This \renewcommand call needs to be put in a .sty style file, since it uses macros containing the @ character. (I just saw Alexey Malistov's answer; the other alternative is the \makeatletter and \makeatother macros.) Use


\usepackage{myletter}

to bring in the new style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文