我想要多行包含三个部分:左对齐的列、居中对齐的中间列和右对齐的最后一列。对于任何一行,这主要通过 \hfill 完成。问题是中间列不是居中对齐的,我希望中间列能够排列在这些多列行的不同实例上。此外,这些行之间还有其他文本,所以我不能使用单个表格。
以下 .tex 演示了该问题:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
% one line, Column two floats in between one and three
\noindent Column one \hfill Column two \hfill Column three
%multiple lines
\noindent Column one
%this line is absolutely centered and is aligned with any other
{\centering \textbf{Column two} \\}
\hfill Column three
Ea vero quando definiebas vix. Velit facete referrentur sit ei. Cu eam exerci labore expetendis. Vel an pertinax inciderint, at suas volumus scriptorem sea, at sed utroque perfecto consulatu.
\noindent This column one is a bit longer \hfill Not lined up \hfill Column three changed
\noindent This column one is a bit longer
{\centering \textbf{Is lined up} \\}
\hfill Column three changed
\noindent This column one is a bit longer \begin{center} no good \end{center} \hfill Column three changed
\noindent This column is a bit longer {\centering Not centered} \hfill Column three changed
% try with tables
\hrulefill
\noindent \begin{tabular*}{\textwidth}{lcr}
Column one & Column two & Column three \\
\hspace{0.30 \textwidth} & \hspace{0.30 \textwidth} & \hspace{0.30 \textwidth}
\end{tabular*}
Ea everti utamur ullamcorper sed, id duo exerci ceteros apeirian, nam ex oratio prodesset. Cu summo oratio populo eum, in euismod sanctus mel, no accumsan explicari elaboraret his.
\noindent \begin{tabular*}{\linewidth}{lcr}
This column one is a bit longer & New column two & Column three changed \\
\hspace{0.30 \linewidth} & \hspace{0.30 \linewidth} & \hspace{0.30 \linewidth}
\end{tabular*}
\end{document}
第一次使用 \hfill 时,由于其他列不同,中间列未对齐。第二次使用 \hfill 时,中间列对齐(粗体),但跨越三行而不是一行。多次尝试将其设置为一行均未成功。
我也尝试过使用表格(位于 \hrulefill 下方),但它会增加我不想要的额外垂直空间,而且我必须手动调整 \textwidth 乘数以匹配边距。在最坏的情况下,我可以这样做并添加负 vspace,但我想知道是否有更好的方法?
答案1
您可以分三部分进行:
\noindent\rlap{left-justified text}\hfill
centered text\hfill
\llap{right-justified text}%
如果后面还有另一行文字,则以 结束\\
,或者仅在段落结尾处留一个空白行。
请记住,如果左侧没有任何文本,则需要放入一个“塞子”,以便初始空间不会消失。
\mbox{}
总是一个很好的塞子。