如何在乳胶中构建表格内的表格

如何在乳胶中构建表格内的表格

我想在乳胶中构建一个像下图这样的表格:

在此处输入图片描述

答案1

只需在表格环境中使用多列即可,如下所示:

\documentclass{article}
 \usepackage[table]{xcolor}
\begin{document}

\begin{tabular}{c|c|c|c|c}
 \multicolumn{5}{c}{ input}\\
 \multicolumn{1}{c}{state}&\multicolumn{1}{c}{a}&\multicolumn{1}{c}{b}&    \multicolumn{1}{c}{c}&\multicolumn{1}{c}{\textit{P}}\\
\cline{2-4}
0&\cellcolor{gray}1&0&0&a\\
\cline{2-4}
1&1&\cellcolor{gray}2&0&b\\
\cline{2-4}
2&\cellcolor{gray}3&0&0&a\\
\cline{2-4}
3&1&\cellcolor{gray}4&0&b\\
\cline{2-4}
\end{tabular}
\end{document}

在此处输入图片描述

改进版本

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{calc}

\begin{document}

\begin{tabular}{c|c|c|c|c}
 \multicolumn{1}{c}{}&
 \multicolumn{3}{c}{input}\\
 \multicolumn{1}{c}{state}&
 \multicolumn{1}{c}{\texttt{a}}&
 \multicolumn{1}{c}{\texttt{b}}&
 \multicolumn{1}{c}{\texttt{c}}&
 \multicolumn{1}{c}{\makebox[\widthof{state}]{$P$}}\\
\cline{2-4}
0 & \cellcolor{gray}1 & 0 & 0 & \texttt{a}\\
\cline{2-4}
1 & 1 & \cellcolor{gray}2 & 0 & \texttt{b}\\
\cline{2-4}
2 & \cellcolor{gray}3 & 0 & 0 & \texttt{a}\\
\cline{2-4}
3 & 1 &\cellcolor{gray}4 & 0 & \texttt{b}\\
\cline{2-4}
\end{tabular}

\end{document}

在此处输入图片描述

相关内容