我正在寻找一种(干净的)方法来在以下情况下保持文本对齐:
thesis under the direction of:
[tab] Title [&] Name [&] University
with the supervision of:
[tab] Title [&] Name [&] University
[tab] Title [&] Name [&] University
[tab] Title [&] Name [&] University
到目前为止,我发现的(肮脏的)方法是凭经验固定第一列和第二列的宽度。这是一个 MWE
\documentclass[11pt]{article}
\begin{document}
\begin{titlepage}
\vspace*{\fill}
\noindent{\emph{thesis under the direction of}}\\[.3cm]
\hspace*{.4cm}\begin{tabular}{p{.1\textwidth}p{.4\textwidth}l}
Title & First Name Last Name & University A\\
\end{tabular}
\vspace*{.5cm}
\noindent{\emph{with the supervision of}}\\[.3cm]
\hspace*{.4cm}\begin{tabular}{p{.1\textwidth}p{.4\textwidth}l}
Title & First Name Last Name & University B\\
Title & First Name Last Name & University C\\
\end{tabular}
\end{titlepage}
\end{document}
我只是好奇想知道是否有一种更清洁、更系统的方法来做到这一点?
谢谢!
答案1
可以使用吗tabbing
?
\begin{tabbing}
\emph{thesis under the direction of} \\
\hspace{.4cm} \= Longest Title \= Longest First Name Last Name \= Longest University A \kill
\> Title \> First Name Last Name \> University A \\[.5cm]
\pushtabs
\emph{with the supervision of} \\
\poptabs
\> Title \> First Name Last Name \> University B \\
\> Title \> First Name Last Name \> University C \\
\end{tabbing}
(这里不需要\pushtabs
和命令,但在其他情况下可能会有用。)\poptabs
答案2
由于您愿意为每列指定最长的条目,因此您可以定义一个宏将文本放在适当大小的框内以产生:
使用\parbox
表示大学名称,这样名称会更长。此段落的宽度设置为 所占的宽度Longest University
。
代码:
\documentclass{article}
\usepackage{calc}
\newcommand*{\Attribution}[3]{%
\par\noindent%
\hspace*{0.5cm}% control leading indent
\makebox[\widthof{Longest Title}][l]{#1}%
\makebox[\widthof{Longest First Name Last Name}][l]{#2}%
\parbox[t]{\widthof{Longest University}}{#3}%
}%
\begin{document}
\noindent
\emph{thesis under the direction of:}
\Attribution{Title}{First Last}{University A}
\bigskip
\noindent
\emph{with the supervision of:}
\Attribution{Title}{First Name Last Name}{University A}
\Attribution{Title}{First Name Last Name}{University B}
\Attribution{Title}{First Name Last Name}{University C}
\Attribution{Title}{First Name Last Name}{University with a really long name}
\end{document}