在 \hfill 环境中对齐文本

在 \hfill 环境中对齐文本

我该如何排列 \hfill 中的文本行?使用表格环境是解决此问题的唯一方法吗?

\documentclass{letter} % Uses 10pt
\usepackage{marvosym} % add the symbols for email and phone contact data
\begin{document}

\begin{flushleft}
{\large\bf First Last}
\end{flushleft}
\medskip\hrule height 1pt
%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\begin{flushright}
\hfill Address, Apt XXX\\
\hfill City, ST ZIP-XXXX\\
\hfill {\Large\Telefon} (XXX)-XXX-XXXX
\end{flushright} 

%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\vfill % forces letterhead to top of page
\end{document}

答案1

例如,使用(完全左)tabular对齐。l@{}

\documentclass{letter} % Uses 10pt
\usepackage{marvosym} % add the symbols for email and phone contact data
\begin{document}

\begin{flushleft}
{\large\bf First Last}
\end{flushleft}
\medskip\hrule height 1pt
%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\begin{flushright}
\begin{tabular}{l@{}}  %% as observed by Werner, use l@{} instead of l
 Address, Apt XXX\\
 City, ST ZIP-XXXX\\
 {\Large\Telefon} (XXX)-XXX-XXXX
\end{tabular}\end{flushright} 

%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\vfill % forces letterhead to top of page
\end{document}

在此处输入图片描述

但如果你想把它们推到右边,只需使用flushright

\begin{flushright}
 Address, Apt XXX\\
 City, ST ZIP-XXXX\\
 {\Large\Telefon} (XXX)-XXX-XXXX
\end{flushright} 

在此处输入图片描述

答案2

您只需将内容放在左对齐即可\Longstack

\documentclass{letter} % Uses 10pt
\usepackage{marvosym} % add the symbols for email and phone contact data
\usepackage[usestackEOL]{stackengine}
\begin{document}

\begin{flushleft}
{\large\bf First Last}
\end{flushleft}
\medskip\hrule height 1pt
%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\begin{flushright}
\hfill 
\Longstack[l]{Address, Apt XXX\\
City, ST ZIP-XXXX\\
{\Large\Telefon} (XXX)-XXX-XXXX}
\end{flushright} 

%%%%%%%%%%% how can I left align the different lines in this flushright ? %%%%%%%%%%%

\vfill % forces letterhead to top of page
\end{document}

在此处输入图片描述

相关内容