Tabular*/tabularx 的列包含对齐方程的行和普通的列

Tabular*/tabularx 的列包含对齐方程的行和普通的列

这是评论中建议的新问题@egreg在回答这个问题时在多个表格行上对齐方程式

因此起点是以下代码:

\documentclass{article}
\usepackage{booktabs,array}

\newcolumntype{A}{
 >{$}r<{$}
 @{\extracolsep{0pt}}
 >{${}} l <{$}
 @{\extracolsep{\fill}}
} % A for "align"
%% (1) "r" column in math mode:          >{$} r <{$}
%% (2) no space:                         @{}
%% (3) "l" column in math mode, with
%%     an empty subformula at the start: >{${}} l <{$}

\begin{document}
\noindent
\begin{tabular*}{\textwidth}{
  @{\hspace{\tabcolsep}\extracolsep{\fill}}
  AAA
  @{\hspace{\tabcolsep}}
}
\toprule
\multicolumn{4}{l}{Header 1} \\
\midrule
a      &= \sum_j b(c) & c     &= d        & aaa &= bbb\\
\midrule
\multicolumn{4}{l}{Header 2} \\
\midrule
e      &= fghij(y)    & qr    &= vwxyzstu & a   &= b\\
klm(x) &= nop         & abcde &< fghij    & x   &= 0\\
\bottomrule
\end{tabular*}
\end{document}

目前的特点有:

  • 表格的宽度由用户指定
  • 数学模式中对齐的列

如何添加不处于数学模式但由 tabular* 或 tabularx 处理的列,以便在列之间均匀分布剩余的空白?

更新列类型为:AccAAl
在 David Carlisle 的评论的帮助下,我可以得到一个运行版本:

\documentclass{article}
\usepackage{booktabs,array}
\newcolumntype{A}{ >{$}r<{$} @{\extracolsep{0pt}} >{${}} l <{$} @{\extracolsep{\fill}} }
\usepackage{blindtext}

\begin{document}
\blindtext
\begin{tabular*}{\textwidth}{
    @{\hspace{\tabcolsep}\extracolsep{\fill}}
    A
    @{\hspace{\tabcolsep}}
    @{\extracolsep{\fill}}c
    @{\extracolsep{\fill}}c
    @{\hspace{\tabcolsep}\extracolsep{\fill}}
    AA
    @{\hspace{\tabcolsep}}
    @{\extracolsep{\fill}}l
  }
  \toprule
  \multicolumn{2}{l}{title 1} & title 2 (c) & title 3 (c) & \multicolumn{2}{c}{title 4} & \multicolumn{2}{c}{title 5} & title 6 (l) \\
  \midrule
  a &= b       & cell 2     &   cell 3     &  c&=d          & e&=f & cell6 \\
  a+2 &= b       & cell 2     &   cell 3     &  c+3&=d          & e+4&=f & cell6 \\
  \bottomrule
\end{tabular*}
\blindtext
\end{document}

问题 如何正确对齐明显是文本而非方程式的列标题。我天真地尝试了这种方法。然而,最明显的是,在第 1 列中,这是不正确的!

答案1

一个(非常)小的变化车牌回答列标题对齐的两种方式(我无法弄清楚,你喜欢如何对齐):

\documentclass{article}
\usepackage{array, booktabs}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
 \newcommand\mc[1]{\multicolumn{1}{c}{#1}}
 \newcommand\mr[1]{\multicolumn{2}{r}{#1}}
\newcolumntype{A}{>{$}r<{$} @{} >{$}l<{$}}
\usepackage{lipsum}

\begin{document}
\lipsum[2]
    \begin{center}
    \begin{tabular*}{\textwidth}{%
        @{\hspace{\tabcolsep}\extracolsep{\fill}}
        A  
        cc 
        AA
        l 
        @{\hspace{\tabcolsep}}  }
        \toprule
\mcc{title 1} & title 2 (c) & title 3 (c) & \mcc{title 4} & \mcc{title 5} & \mc{title 6 (l)}    \\
        \midrule
a   & = b    & cell 2      &   cell 3    &  c   & = d   & e     & = f  & cell 66666666        \\
a+2 & = b    & cell 2      &   cell 3    &  c+3 & = d   & e+4   & = f  & cell 6         \\
        \bottomrule
    \end{tabular*}
    \end{center}

    \begin{center}
    \begin{tabular*}{\textwidth}{%
        @{\hspace{\tabcolsep}\extracolsep{\fill}}
        A
        cc
        AA
        l
        @{\hspace{\tabcolsep}}  }
        \toprule
\mr{title 1} & title 2 (c) & title 3 (c) & \mr{title 4} & \mr{title 5} & title 6 (l)    \\
        \midrule
a   & = b    & cell 2      &   cell 3    &  c   & = d   & e     & = f  & cell 6 66666666\\
a+2 & = b    & cell 2      &   cell 3    &  c+3 & = d   & e+4   & = f  & cell 6         \\
        \bottomrule
    \end{tabular*}
    \end{center}

    \lipsum[2]
\end{document}

在此处输入图片描述

答案2

我认为您的意图是这样的(包括@{}在的第二个参数中\multicolumn):

\documentclass{article}
\usepackage{booktabs,array}
\newcolumntype{A}{
    >{$}r<{$}
    @{\extracolsep{0pt}}
    >{${}} l <{$}
    @{\extracolsep{\fill}}
}
\usepackage{blindtext}

\begin{document}
    \blindtext
    \vspace{\baselineskip}

    \noindent
    \begin{tabular*}{\textwidth}{ @{\hspace{\tabcolsep}\extracolsep{\fill}}
            AccAAl
            @{\hspace{\tabcolsep}}}
        \toprule
        \multicolumn{2}{r@{}}{title 1} & title 2 (c) & title 3 (c) & \multicolumn{2}{r@{}}{title 4} & \multicolumn{2}{r@{}}{title 5} & title 6 (l) \\
        \midrule
        a &= b       & cell 2     &   cell 3     &  c&=d          & e&=f & cell6 \\
        a+2 &= b       & cell 2     &   cell 3     &  c+3&=d          & e+4&=f & cell6 \\
        \bottomrule
    \end{tabular*}
    \vspace{\baselineskip}

    \blindtext
\end{document}

在此处输入图片描述

相关内容