【问题标题】:Getting two tables in LaTeX to have the same (right-aligned) column width让 LaTeX 中的两个表格具有相同的(右对齐)列宽
【发布时间】:2011-01-18 16:57:36
【问题描述】:

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

\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 包,那么其他解决方案也很棒。

【问题讨论】:

  • 不是这样的问题的答案,但我使用 currvita 包来维护我的简历(好吧,有合适的黑客......):ctan.org/tex-archive/macros/latex/contrib/currvita。这样就不必处理这些细节了。
  • 感谢您的提示,下个版本请查看 :)

标签: alignment latex tabular


【解决方案1】:

如果您使用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}

给予:

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

【讨论】:

    【解决方案2】:

    这是@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 运行。

    【讨论】:

    • 为了完成,我会注意,如果你想将该规范放在最后一列,你需要使用\arraybackslash重置“\\”的含义。
    • 嘿,不知道,你能详细说明一下吗?
    • \raggedleft 改变了\\ 的含义来做各种神奇的事情。见{\ttfamily\meaning\raggedleft}\arraybackslash 将其含义更改回表格环境的含义。这些更改仅影响当前组,因此您只会在最后一列中看到编译错误。
    【解决方案3】:

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

    \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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

        您可以使用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}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-16
          • 2012-08-24
          • 1970-01-01
          • 2012-07-28
          • 2017-05-20
          • 2019-01-12
          相关资源
          最近更新 更多