让 LaTeX 中的两个表格具有相同(右对齐)的列宽

发布于 2024-08-21 23:49:35 字数 927 浏览 10 评论 0原文

我有两个非常短且连续的部分(对于简历),每个部分都包含一个小表格:

\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}

因此每个表格都有两列:第一列包含句点,向右对齐。第二个:更多具有一定宽度的信息,顶部(和左侧)对齐。

问题是两个表格中左列的宽度不同,并且看起来不太好,因为这些部分(因此表格)是连续的并且在一页中。我不能给 rp 这样的宽度:

\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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

太阳哥哥 2024-08-28 23:49:35

如果您使用 array 包,则可以将 \hfill 放在标头中,如下所示,这样您就不必记住将其(或 \parbox) 在每行中。

\documentclass{article}
\usepackage{multicol}
\usepackage{array}
\begin{document}
\section{Work Experience}

\begin{tabular}{>{\hfill}p{5cm}|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}{>{\hfill}p{5cm}|p{11cm}}
  Slightly wider first column & University, Town \\
  Jan 2009 & Thesis subject \\
  & A description of what you did\\
  \multicolumn{2}{c}{} 
\end{tabular}
\end{document}

给出:

替代文本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.

\documentclass{article}
\usepackage{multicol}
\usepackage{array}
\begin{document}
\section{Work Experience}

\begin{tabular}{>{\hfill}p{5cm}|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}{>{\hfill}p{5cm}|p{11cm}}
  Slightly wider first column & University, Town \\
  Jan 2009 & Thesis subject \\
  & A description of what you did\\
  \multicolumn{2}{c}{} 
\end{tabular}
\end{document}

to give:

alt text http://www.freeimagehosting.net/uploads/5e29f675e3.jpg

那片花海 2024-08-28 23:49:35

这是 @RTBarnard 使用 tabularx 包的答案的变体:

\documentclass[a4paper,twoside,draft,12pt]{article}
\usepackage{tabularx}
\begin{document}

\section{Work Experience}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\end{tabularx}

\section{Education}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Somewhat wider than first column, 
overflowing into additional lines & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\end{tabularx}
\end{document}

注意:

  1. 为什么使用 tabularx?因为很多时候
    更容易知道您的宽度
    可用于整个表,并且
    让 TeX 计算未知数
    列宽。
  2. 第一个参数是整个表格的宽度。在这里,我指定了 \textwidth 来填充类型块的宽度,但您可以将其更改为您需要的任何尺寸。
  3. 我使用了 \raggedright 而不是 \hfill:如果项目流到第二行,\hfill 将仅右对齐第一行段落的行。
  4. \multicol 重要吗?我已删除它以使答案尽可能简单。

在 TeXLive 下使用 XeTeX 运行。

Here's a variant of @RTBarnard's answer using the tabularx package:

\documentclass[a4paper,twoside,draft,12pt]{article}
\usepackage{tabularx}
\begin{document}

\section{Work Experience}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\end{tabularx}

\section{Education}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Somewhat wider than first column, 
overflowing into additional lines & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\end{tabularx}
\end{document}

Notes:

  1. Why tabularx? Because it's often
    easier to know the width you have
    available for the whole table, and
    to let TeX calculate the unknown
    column widths.
  2. The first parameter is the overall table width. Here, I've specified \textwidth to fill the width of typeblock, but you can change that to whatever measure you need.
  3. I've used \raggedright rather than \hfill: if the item flows onto a second line, \hfill will only right-align the first line of the paragraph.
  4. Was the \multicol significant? I've removed it to keep the answer as simple as possible.

Run with XeTeX under TeXLive.

呆橘 2024-08-28 23:49:35

这是一种包含多种可能性的解决方案:

\begin{tabular}{r|p{11cm}}
\parbox{11cm}{\hfill Current} & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\ 
\end{tabular}

基本上,创建一个具有所需宽度的 \parbox 并在左侧放置一个 \hfill

Here's one solution of many possibilities:

\begin{tabular}{r|p{11cm}}
\parbox{11cm}{\hfill Current} & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\ 
\end{tabular}

Basically, create a \parbox with the desired width and put an \hfill at the left.

黑凤梨 2024-08-28 23:49:35

您可以提供两个 p{width} 选项,并以 \hfill 开始左侧的每个单元格。

You can give both p{width} options, and start each cell in the left with an \hfill.

万劫不复 2024-08-28 23:49:35

您可以使用 array 包为第一列中的每一行指定填充命令:

\begin{tabular}{>{\hfill}p{11cm}|p{11cm}|}

例如:

\documentclass{article}
\usepackage{array}
\begin{document}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
This is a test & test
\end{tabular}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
Test & this is a test
\end{tabular}
\end{document}

You can use array package to specify a fill command for each row in your first column:

\begin{tabular}{>{\hfill}p{11cm}|p{11cm}|}

For example:

\documentclass{article}
\usepackage{array}
\begin{document}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
This is a test & test
\end{tabular}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
Test & this is a test
\end{tabular}
\end{document}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文