tabularx 表中的多重对齐

tabularx 表中的多重对齐

我想创建一个 2 列表,其中第一列水平和垂直居中,而第二列仅向左对齐。我想出了以下代码,但看起来不太好。你能给我一些建议吗?谢谢!

\begin{center}
\begin{tabularx}{\textwidth}{ p{30 mm} | >{\arraybackslash}X  }
  Cas & $\Delta_{\alpha}$ \\
   \hline
   $x_1 < x_2, y_1, y_2$ & $\alpha - \big[w_{22'} + \mu(1)(R_{max} - w_{21'} - w_{22'}) +  \nu(1')(w_{21'} - w_{22'}) \big]$\\ 
   \hline
   $x_2 < x_1, y_1, y_2$ & $\alpha - \big[R_{max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{max}) + \nu(1)(w_{11'} - w_{12'}) \big]$ \\
   \hline
   $y_1 < x_1, x_2, y_2$ & $\alpha - \big[w_{22'} + \mu(1)(w_{12'}  - w_{22'}) + \nu(1)(R_{max} - w_{12'} - w_{22'}) \big]$ \\
   \hline
   $y_2 < x_1, x_2, y_1$ & $\alpha - \big[R_{max} - w_{11'} + \mu(1)(w_{11'} - w_{21'}) + \nu(1)(w_{11'} + w_{21'} - R_{max}) \big] $ \\
   \hline
   $x_1 = y_1 < x_2 = y_2$ & $\alpha - \big[w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (R_{max} - w_{21'} - w_{12'})  \big]$\\ 
   \hline
   $x_1 = y_2 < x_2 = y_1$ & $\alpha - \big[w_{22'} + \mu(1)(R_{max} - w_{21'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{max})  \big]$ \\
   \hline
   $x_2 = y_1 < x_1 = y_2$ & $\alpha - \big[w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(R_{max} - w_{12'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{max})  \big]$ \\
   \hline
   $x_2 = y_2 < x_1 = y_1$ & $\alpha - \big[R_{max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{max}) + \nu(1')(w_{11'} + w_{21'} - R_{max}) + \mu(1) \nu(1') (R_{max} - w_{12'} - w_{21'}) \big]$ \\
   \hline
   $x_1 = x_2 = y_1 = y_2$ & $\alpha - \big[w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} + w_{22'} - w_{12'} - w_{21'}) \big]$
 \end{tabularx} 
\end{center}

答案1

以下是一些建议(无特定顺序):

  • 使用c而不是p作为第一列的列类型。实际上,我认为l这样更好,所以我在下面的代码中使用了它。

  • 继续使用tabularx环境,并运行\renewcommand\tabularxcolumn[1]{m{#1}}以对非列实施垂直居中(而不是顶部对齐X

  • 使用>{$}l<{$}and>{$}L<{$}而不是land来启用自动数学模式L。这样,您可以摆脱$表中的大量符号;反过来,这确实有助于整理代码。

  • 无需放大方括号。

  • 删除垂直规则,加载booktabs包,并\hline根据需要用\midrule或替换\addlinespace。请记住,空格可以作为与实线一样有效的分隔符。考虑\bottomrule在环境底部使用 — — 您猜对了 — — tabularx

  • R_{\max},不是R_{max}

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage{booktabs}   % for well-spaced horizontal rules
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}
\begin{center}
\begin{tabularx}{\textwidth}{@{} >{$}l<{$} >{$}L<{$} @{}}
   \mbox{Cas} & \Delta_{\alpha} \\
   \midrule
   x_1 < x_2, y_1, y_2 & \alpha - [w_{22'} + \mu(1)(R_{\max} - w_{21'} - w_{22'}) +  \nu(1')(w_{21'} - w_{22'}) ]\\ 
   \addlinespace
   x_2 < x_1, y_1, y_2 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{\max}) + \nu(1)(w_{11'} - w_{12'}) ] \\
   \addlinespace
   y_1 < x_1, x_2, y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'}  - w_{22'}) + \nu(1)(R_{\max} - w_{12'} - w_{22'}) ] \\
   \addlinespace
   y_2 < x_1, x_2, y_1 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} - w_{21'}) + \nu(1)(w_{11'} + w_{21'} - R_{\max}) ]  \\
   \addlinespace
   x_1 = y_1 < x_2 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (R_{\max} - w_{21'} - w_{12'})  ]\\ 
   \addlinespace
   x_1 = y_2 < x_2 = y_1 & \alpha - [w_{22'} + \mu(1)(R_{\max} - w_{21'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{\max})  ] \\
   \addlinespace
   x_2 = y_1 < x_1 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(R_{\max} - w_{12'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{\max})  ] \\
   \addlinespace
   x_2 = y_2 < x_1 = y_1 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{\max}) + \nu(1')(w_{11'} + w_{21'} - R_{\max}) + \mu(1) \nu(1') (R_{\max} - w_{12'} - w_{21'}) ] \\
   \addlinespace
   x_1 = x_2 = y_1 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} + w_{22'} - w_{12'} - w_{21'}) ] \\
   \bottomrule
\end{tabularx} 
\end{center}

\end{document}

答案2

表格代码要短得多,您将愿意使用该 tabularray包:

\documentclass{article} % or some other suitable document class
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\[
\begin{tblr}{colspec = {@{} c X[l,m] @{}},
             rowsep=4pt
             }
   \mbox{Cas} & \Delta_{\alpha}     \\
   \hline
x_1 < x_2, y_1, y_2 & \alpha - [w_{22'} + \mu(1)(R_{\max} - w_{21'} - w_{22'}) +  \nu(1')(w_{21'} - w_{22'}) ]        \\

x_2 < x_1, y_1, y_2 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{\max}) + \nu(1)(w_{11'} - w_{12'}) ] \\

y_1 < x_1, x_2, y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'}  - w_{22'}) + \nu(1)(R_{\max} - w_{12'} - w_{22'}) ] \\

y_2 < x_1, x_2, y_1 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} - w_{21'}) + \nu(1)(w_{11'} + w_{21'} - R_{\max}) ]  \\

x_1 = y_1 < x_2 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (R_{\max} - w_{21'} - w_{12'})  ]\\

x_1 = y_2 < x_2 = y_1 & \alpha - [w_{22'} + \mu(1)(R_{\max} - w_{21'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{\max})  ] \\

x_2 = y_1 < x_1 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(R_{\max} - w_{12'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} - w_{22'} - R_{\max})  ] \\

x_2 = y_2 < x_1 = y_1 & \alpha - [R_{\max} - w_{11'} + \mu(1)(w_{11'} + w_{12'} - R_{\max}) + \nu(1')(w_{11'} + w_{21'} - R_{\max}) + \mu(1) \nu(1') (R_{\max} - w_{12'} - w_{21'}) ] \\

x_1 = x_2 = y_1 = y_2 & \alpha - [w_{22'} + \mu(1)(w_{12'} - w_{22'}) + \nu(1')(w_{21'} - w_{22'}) + \mu(1) \nu(1') (w_{11'} + w_{22'} - w_{12'} - w_{21'}) ] \\
   \hline
\end{tblr}
\]
\end{document}

在此处输入图片描述

相关内容