沿发件人地址动态定位 \closing

沿发件人地址动态定位 \closing

在我们在学校学到的格式中, 的位置\closing与发件人的地址对齐。在下面给出的 MWE 中:我必须通过制定 的规范来\closing目测调整 的位置。有没有办法自动完成这个?\setlength\longindentation

我的 MWE:

\documentclass[a4paper,12pt]{letter}
\usepackage[top=1.5cm, left=2.0cm, right=1.5cm, bottom=1.5cm]{geometry}

\usepackage[sfdefault]{atkinson}
\usepackage{microtype}

\setlength\parindent{0cm}           % Paragraph indentation


%%% Adjusting the \closing specifications:
%1. Decreases the default gap between the closing remark (Warrm regards) and the senders name.
%2. Looking to make its position align with the sender's address.
\renewcommand\closing[1]{\par\nobreak\vspace{\parskip}%
\stopbreaks%
\noindent%
\ifx\@empty\fromaddress\else%
\hspace*{\longindentation}\fi%
\parbox{\indentedwidth}{\raggedright%
\ignorespaces #1\\[\medskipamount]%
\ifx\@empty\fromsig%
\fromname%
\else \fromsig \fi\strut}%
\par}
%%%%


\signature{Ginko Mitten}
\address{21 Jump Street,\\Mink Road,\\ Uganda}

%%%% dynamic adjustment of closing position %%%
\setlength{\longindentation}{0.78\textwidth}
%%%%%%%%


\begin{document}
\begin{letter}{%
Prof. Minao Sloan,\\
Room 45,\\
University of Computation,\\
Mexico City,\\
Mexico}

\opening{%
\begin{center}
\textbf{Subject}: Our meeting next month.
\end{center}%
Dear Prof. Sloan}

Blah Blah Blah. Quantum computing very interesting. Blah blah blah.\par

Thank you very much for your time. I hope to get in touch with you soon.

\closing{Warm regards,}


\end{letter}
\end{document}

答案1

您需要在 的重新定义周围使用\makeatletter和,否则将\makeatother\closing\ifx\@empty...总是返回 false 因为它\@与进行比较e

现在让我们解决您的问题:您想要测量“发件人地址”和日期,因此您可以使用\parbox相同尺寸的。

\documentclass[a4paper,12pt]{letter}
\usepackage[top=1.5cm, left=2.0cm, right=1.5cm, bottom=1.5cm]{geometry}

\usepackage[sfdefault]{atkinson}
\usepackage{microtype}

%%% Adjusting the \closing specifications:
%1. Decreases the default gap between the closing remark (Warrm regards) and the senders name.
%2. Looking to make its position align with the sender's address.
\makeatletter
\renewcommand\closing[1]{%
  \par\nobreak\vspace{\parskip}%
  \stopbreaks
  \ifx\@empty\fromaddress\else
    \hspace*{\fill}%
  \fi
  \sbox0{\begin{tabular}{@{}l@{}}\fromaddress\\\today\end{tabular}}%
  \parbox[t]{\wd0}{%
    \raggedright
    \ignorespaces #1\\[\medskipamount]
    \ifx\@empty\fromsig
      \fromname
    \else
      \fromsig
    \fi
    \strut
  }%
  \par
}
\makeatother
%%%%


\signature{Ginko Mitten}
\address{21 Jump Street,\\Mink Road,\\ Uganda}

\begin{document}
\begin{letter}{%
Prof. Minao Sloan,\\
Room 45,\\
University of Computation,\\
Mexico City,\\
Mexico}

\opening{%
\begin{center}
\textbf{Subject}: Our meeting next month.
\end{center}%
Dear Prof. Sloan}

Blah Blah Blah. Quantum computing very interesting. Blah blah blah.\par

Thank you very much for your time. I hope to get in touch with you soon.

\closing{Warm regards,}

\end{letter}

\end{document}

(不过,我并不认为这有什么吸引力。)

在此处输入图片描述

相关内容