右对齐地址

右对齐地址

我对 LaTeX 还不太熟悉,在写动机信时遇到了一些问题。我脑子里有一个不错的结构,但我无法完全完成它。

这是一个实例:点击。一切看起来都很好,但我仍然遇到的唯一问题是,我希望\address{}字段内容显示为右对齐,而不是在右对齐但内容左对齐的块内。

我已经寻找过解决方案,但没有发现任何有效的方法。

答案1

在这里,我使用右对齐\Longstack来完成它,但是有几个怪癖(编辑以处理长名称和短名称条件):

1)我必须将堆栈放在与 宽度相同的右对齐框中\today,以处理名称长度超过或者比日期短;

2)我必须明确将\Longstack间隙设置为 12pt,因为\baselineskip在 内部归零\address

在下面的 MWE 中,您可以取消注释名称的扩展部分,以查看它是否也适用于长名称。

\documentclass{letter}
\addtolength{\voffset}{-0.5in}
\addtolength{\hoffset}{-0.3in}
\addtolength{\textheight}{2cm}

\longindentation=0pt

\signature{My Name}

\usepackage[usestackEOL]{stackengine}
\setstackgap{L}{12pt}
\address{\makebox[\widthof{\today}][r]{\Longstack[r]{\textbf{My %very long 
  name}\\address\\phone\\email}}}

\begin{document}

\begin{letter}{}

\opening{\textbf{Job title goes here}}

Dear mister M,

Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Thank you for your time and consideration.

I look forward to your reply.

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\end{letter}

\end{document}

在此处输入图片描述

答案2

您还可以使用它tabular来定义地址,并让日期也右对齐,您可以重新定义\@date

在此处输入图片描述

代码:

\documentclass{letter}

\signature{My Name}

\makeatletter
\let\Date\@date
\renewcommand{\@date}{\hfill\Date}%
\makeatother

\address{\begin{tabular}{r@{}}%
    \textbf{My name is pretty long}\\
    address                        \\
    phone                          \\
    email                          \\
    \phantom{\today}              \\
    \end{tabular}%  
    }

\begin{document}

\begin{letter}{}

\opening{\textbf{Job title goes here}}

Dear mister M,
 
Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Vivamus consectetur, mauris sit amet pharetra pharetra, tortor ante dignissim purus, vitae pellentesque ante lorem eu magna. Morbi at leo leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed feugiat volutpat risus, a ullamcorper magna dictum quis. Nam dictum enim et lectus consectetur consectetur. Vestibulum vitae eros vel elit venenatis ornare ac sed felis. Nunc et laoreet libero. Cras ut fermentum dui.

Thank you for your time and consideration.

I look forward to your reply.
\hfill\smash{\rule{1pt}{8in}}

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\end{letter}
 
\end{document}

答案3

而不是使用:

\address{Name Surname\\
 School of XYZ\\
 Location\\
 State Zip Code, Country\\
 [email protected]}

只需注释掉几行并使用 \flushright 环境,如下所示:

\begin{flushright}
%\address{
    Name Surname\\
     School of XYZ\\
     Location\\
     State Zip Code, Country\\
     [email protected]
%}
\end{flushright}

相关内容