我怎样才能创建这样的表格

我怎样才能创建这样的表格

MWE 如下

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}


\begin{document}

\[
\begin{array}{|c|c|c|c|c|c|c|c|c|}
\hline & & & \begin{array}{l}
\text{Basis Inverse} \\
B_1^{-1}
\end{array} & & & & & \\
\hline B & X_B & \begin{array}{l}
\beta_0 \\
Z^{\prime}
\end{array} & \begin{array}{l}
\beta_1 \\
S_1
\end{array} & \begin{array}{l}
\beta_2 \\
S_2
\end{array} & \begin{array}{c}
y_1 \\
c_k-Z_k
\end{array} & \begin{array}{c}
\text { Min Ratio } \\
\frac{X_B}{y_1}
\end{array}  & x_1 & x_2 \\
\hline Z^{\prime} & 0 & 1 & 0 & 0 & -1 & - & -1 & -1 \\
\hline S_1 & 6 & 0 & 1 & 0 & 2 & 3 & 2 & 5 \\
\hline S_2 & 2 & 0 & 0 & 1 & 1 & 2 & 1 & 1 \\
\hline
\end{array}
\]

\end{document}

答案1

\multicolumn您可以在数组中使用(与表格相同)。棘手的是均匀划分子列。

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{mathtools}% for mathmakebox
\usepackage{bm}% bold math

\newsavebox{\tempboxa}
\newsavebox{\tempboxb}

\begin{document}

\savebox\tempboxa{\textbf{\begin{tabular}{@{}c@{}}
  Additonal\\
  Table
\end{tabular}}}% measure width

\savebox\tempboxb{$\begin{array}{@{}c@{}}
\textbf{Basis Inverse} \\
\bm{B_1^{-1}}
\end{array}$}% measure width

\[
\begin{array}{|c|c|c|c|c|c|c|c|c|}
\hline & & \multicolumn{3}{c|}{\usebox\tempboxb}
  & & & \multicolumn{2}{c|}{\usebox\tempboxa}\\
\hline \bm{B} & \bm{X_B} & \mathmakebox[\dimexpr 0.333\wd\tempboxb-1.333\arraycolsep]{\begin{array}{@{}l@{}}
\bm{\beta_0} \\
\bm{Z^{\prime}}
\end{array}} & \mathmakebox[\dimexpr 0.333\wd\tempboxb-1.333\arraycolsep]{\begin{array}{@{}l@{}}
\bm{\beta_1} \\
\bm{S_1}
\end{array}} & \mathmakebox[\dimexpr 0.333\wd\tempboxb-1.333\arraycolsep]{\begin{array}{@{}l@{}}
\bm{\beta_2} \\
\bm{S_2}
\end{array}} & \begin{array}{@{}c@{}}
\bm{y_1} \\
\bm{c_k-Z_k}
\end{array} & \begin{array}{@{}c@{}}
\textbf {Min Ratio} \\
\bm{\frac{X_B}{y_1}}
\end{array}  &
  \mathmakebox[\dimexpr 0.5\wd\tempboxa-\arraycolsep]{\bm{x_1}} &
  \mathmakebox[\dimexpr 0.5\wd\tempboxa-\arraycolsep]{\bm{x_2}} \\
\hline Z^{\prime} & 0 & 1 & 0 & 0 & -1 & - & -1 & -1 \\
\hline S_1 & 6 & 0 & 1 & 0 & 2 & 3 & 2 & 5 \\
\hline S_2 & 2 & 0 & 0 & 1 & 1 & 2 & 1 & 1 \\
\hline
\end{array}
\]

\end{document}

演示

答案2

这里有一个使用的可能性。1×1 块允许您在单元格中nicematrix使用。\\

每次进行更改时都必须编译两次。

在此处输入图片描述

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb,nicematrix,bm}


\begin{document}

\[
\NiceMatrixOptions{cell-space-limits = 5pt}
\begin{NiceArray}{cc*3{w{c}{1cm}}cc*2{w{c}{1cm}}}[hvlines]
%  2 centered columns, 3 fixed-width centered columns, 2 centered columns, 2 fixed-width centered columns
 & & \Block{1-3}{\textup{Basis Inverse}\\B_1^{-1}} & & & & & \Block{1-2}{\textup{Additional}\\\textup{Table}}\\
\bm{B} & \bm{X_B} & \Block{1-1}{\bm{\beta_0}\\\bm{Z'}} & \Block{1-1}{\bm{\beta_1}\\\bm{S_1}} &
    \Block{1-1}{\bm{\beta_2}\\\bm{S_2}} & \Block{1-1}{\bm{y_1}\\\bm{c_k-Z_k}} & 
    \Block{1-1}{\textbf{Min Ratio}\\\dfrac{\bm{X_B}}{\bm{y_1}}} & \bm{x_1} & \bm{x_2} \\
Z' & 0 & 1 & 0 & 0 & -1 & - & -1 & -1 \\
S_1 & 6 & 0 & 1 & 0 & 2 & 3 & 2 & 5 \\
S_2 & 2 & 0 & 0 & 1 & 1 & 2 & 1 & 1
\end{NiceArray}
\]

\end{document}

答案3

\documentclass[12pt,a4paper]{article}

\begin{document}
\[ 
\renewcommand{\arraystretch}{2.2}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline \multirow[b]{2}{*}{$B$} & \multirow[b]{2}{*}{$X_B$} & \multicolumn{5}{|c|}{ Basis Inverse $B_1^{-1}$} & \multirow[b]{2}{*}{\begin{tabular}{c}
$y_1$ \\[-0.5em]
$C_k - Z_k$
\end{tabular}} & \multirow[b]{2}{*}{\begin{tabular}{c}
Min Ratio \\[-0.5em]
$\dfrac{X_B}{y_1}$
\end{tabular}} & \multicolumn{3}{|c|}{ Additional table } \\
\hline & & \begin{tabular}{c}
$\beta_0$ \\
$Z$
\end{tabular} & \begin{tabular}{l}
$\beta_1$ \\
$S_1$
\end{tabular} & \begin{tabular}{l}
$\beta_2$ \\
$S_2$
\end{tabular} & \begin{tabular}{l}
$\beta_3$ \\
$S_3$
\end{tabular} & \begin{tabular}{l}
$\beta_4$ \\
$S_4$
\end{tabular} & & & $x_1$ & $x_2$ & $x_3$ \\
\hline$Z$ & 0 & 1 & 0 & 0 & 0 & 0 & & - & -19500 & -23000 & -6250 \\
\hline$S_1$ & 70 & 0 & 1 & 0 & 0 & 0 & & - & 10 & 10 & 50 \\
\hline$S_2$ & 12 & 0 & 0 & 1 & 0 & 0 & & - & 3 & 7 & 2 \\
\hline$S_3$ & 25 & 0 & 0 & 0 & 1 & 0 & & - & 5 & 10 & 10 \\
\hline$S_4$ & 16 & 0 & 0 & 0 & 0 & 1 & & - & 3 & 8 & 5 \\
\hline
\end{tabular}
\]

\end{document}

相关内容