让 LaTeX 中的两个表格具有相同(右对齐)的列宽
我有两个非常短且连续的部分(对于简历),每个部分都包含一个小表格:
\section{Work Experience}
\begin{tabular}{r|p{11cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\
\end{tabular}
\section{Education}
\begin{tabular}{r|p{11cm}}
Slightly wider first column & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\multicolumn{2}{c}{}\
\end{tabular}
因此每个表格都有两列:第一列包含句点,向右对齐。第二个:更多具有一定宽度的信息,顶部(和左侧)对齐。
问题是两个表格中左列的宽度不同,并且看起来不太好,因为这些部分(因此表格)是连续的并且在一页中。我不能给 r
像 p
这样的宽度:
\begin{tabular}{r{11cm}|p{11cm}}
不起作用。如何使两个表的第一列的宽度具有相同的长度,同时使它们正确对齐?
编辑感谢您的答案,它们都对我有用,所以我对所有答案都投了赞成票,并接受了对我最有吸引力(也是最多赞成票)的答案,因为您不必指定每行中的 \hfill
。但是,如果您出于任何原因不想使用 array 包,那么其他解决方案也很棒。
I have two very short and consecutive sections (for a CV), each containing a small table:
\section{Work Experience}
\begin{tabular}{r|p{11cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\
\end{tabular}
\section{Education}
\begin{tabular}{r|p{11cm}}
Slightly wider first column & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\multicolumn{2}{c}{}\
\end{tabular}
So each table has two columns: The first containing the period, aligned to the right. The second: some more info with a certain width, top (and left) aligned.
The problem is that the width of the left column in the two tables is different, and doesn't look nice since the sections (therefore tables) are consecutive and in one page. I cannot give r
a width like p
:
\begin{tabular}{r{11cm}|p{11cm}}
Does not work. How can I get the widths of the first columns of the two tables the same length while also having them right aligned?
EDIT Thanks for the answers, they all work for me so I upvoted all of them, and accepted the one that appealed to me the most (and most upvoted), since you don't have to specify the \hfill
in each row. However if you don't want to use the array package for any reason then the other solutions are also great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用
array
包,则可以将\hfill
放在标头中,如下所示,这样您就不必记住将其(或\parbox
) 在每行中。给出:
替代文本http://www.freeimagehosting.net/uploads/5e29f675e3.jpg
If you use the
array
package, you can put the\hfill
in the header as follows, so you don't have to remember to put it (or a\parbox
) in each row.to give:
alt text http://www.freeimagehosting.net/uploads/5e29f675e3.jpg
这是 @RTBarnard 使用
tabularx
包的答案的变体:注意:
tabularx
?因为很多时候更容易知道您的宽度
可用于整个表,并且
让 TeX 计算未知数
列宽。
\textwidth
来填充类型块的宽度,但您可以将其更改为您需要的任何尺寸。\raggedright
而不是\hfill
:如果项目流到第二行,\hfill
将仅右对齐第一行段落的行。\multicol
重要吗?我已删除它以使答案尽可能简单。在 TeXLive 下使用 XeTeX 运行。
Here's a variant of @RTBarnard's answer using the
tabularx
package:Notes:
tabularx
? Because it's ofteneasier to know the width you have
available for the whole table, and
to let TeX calculate the unknown
column widths.
\textwidth
to fill the width of typeblock, but you can change that to whatever measure you need.\raggedright
rather than\hfill
: if the item flows onto a second line,\hfill
will only right-align the first line of the paragraph.\multicol
significant? I've removed it to keep the answer as simple as possible.Run with XeTeX under TeXLive.
这是一种包含多种可能性的解决方案:
基本上,创建一个具有所需宽度的
\parbox
并在左侧放置一个\hfill
。Here's one solution of many possibilities:
Basically, create a
\parbox
with the desired width and put an\hfill
at the left.您可以提供两个 p{width} 选项,并以
\hfill
开始左侧的每个单元格。You can give both p{width} options, and start each cell in the left with an
\hfill
.您可以使用 array 包为第一列中的每一行指定填充命令:
例如:
You can use
array
package to specify a fill command for each row in your first column:For example: