我正在使用表格环境绘制网格结构。有些单元格是空的,有些单元格已填充,有些单元格包含符号。没什么特别的。
\documentclass{article}
\usepackage[table]{xcolor}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\setlength{\extrarowheight}{3pt} %for superscripts in tabular
\begin{document}
\newcommand{\xx}{\cellcolor[gray]{0.5}}
\begin{table}[h]
\centering
{\tt
\begin{tabular}{ *{11}{| C{0.4cm}}| }
\hline
N & & \xx & & N & & \xx & & & & \\ \hline
& N & & N & & N & & N & & \xx & \\ \hline
& & & & & & \xx & & & \xx & \xx \\ \hline
\xx & & \xx & & & & & \xx & & & \\ \hline
& & \xx & & & & \xx & & & & \\ \hline
& \xx & & & & \xx & & & & & \\ \hline
& & & & & & \xx & & & & \xx \\ \hline
& & & \xx & \xx & \xx & & & & \xx & \\ \hline
\xx & & & & & & & & & \xx & \\ \hline
\xx & & & & & & & \xx & & \xx & \xx \\ \hline
& \xx & & & & & \xx & \xx & \xx & \xx & \xx \\ \hline
\end{tabular}}
\end{table}
\end{document}
不过,我尝试做的是添加括号,将空单元格分成四个组。当我简单地将 [ 和 ] 添加到单元格内容时,我遇到了一个问题:内容不再适合单元格,并且会换行到略低于原始行的一行(在此过程中垂直扩展了单元格),因为宽度已设置。括号也会居中,因为这是我的单元格的默认行为。
有人能建议我如何模仿下图所示的行为吗?也许是某种不影响表格本身绘制的覆盖?请注意,我可以手动将 [ 和 ] 插入正确的位置,因此无需自动计算四个空字段。
答案1
显示了您的原始数据和我提出的数据。我不确定是否可以在单元格中放置括号。已编辑以修改括号的大小和位置。已重新编辑以允许在带括号的单元格中显示可选内容。
\documentclass{article}
\usepackage[table]{xcolor}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\setlength{\extrarowheight}{3pt} %for superscripts in tabular
\usepackage{scalerel}
\begin{document}
\newcommand{\xx}{\cellcolor[gray]{0.5}}
\begin{table}[h]
\centering
{\tt
\begin{tabular}{ *{11}{| C{0.4cm}}| }
\hline
N & & \xx & & N & & \xx & & & & \\ \hline
& N & & N & & N & & N & & \xx & \\ \hline
& & & & & & \xx & & & \xx & \xx \\ \hline
\xx & & \xx & & & & & \xx & & & \\ \hline
& & \xx & & & & \xx & & & & \\ \hline
& \xx & & & & \xx & & & & & \\ \hline
& & & & & & \xx & & & & \xx \\ \hline
& & & \xx & \xx & \xx & & & & \xx & \\ \hline
\xx & & & & & & & & & \xx & \\ \hline
\xx & & & & & & & \xx & & \xx & \xx \\ \hline
& \xx & & & & & \xx & \xx & \xx & \xx & \xx \\ \hline
\end{tabular}}
\end{table}
\newcommand\lb[1][]{\raisebox{.3ex}{\scaleto[.7ex]{[}{3ex}\makebox[4.45ex]{#1}}\hfill}
\newcommand\rb[1][]{\hfill\makebox[4.4ex]{#1}\raisebox{.3ex}{\scaleto[.7ex]{]}{3ex}}}
\begin{table}[h]
\centering
{\tt
\tabcolsep=0pt
\begin{tabular}{ *{11}{| C{0.82cm}}| }
\hline
N & & \xx & & N & & \xx & \lb & & & \rb \\ \hline
& N & & N & & N & & N & & \xx & \\ \hline
\lb[a] & & &\rb[b2]& & & \xx & & & \xx & \xx \\ \hline
\xx & & \xx & & & & & \xx & & & \\ \hline
& & \xx & & & & \xx & & & & \\ \hline
& \xx & & & & \xx & & & & & \\ \hline
& & & & & & \xx & & & & \xx \\ \hline
& & & \xx & \xx & \xx & & & & \xx & \\ \hline
\xx & & & & & & & & & \xx & \\ \hline
\xx & & & & & & & \xx & & \xx & \xx \\ \hline
& \xx & & & & & \xx & \xx & \xx & \xx & \xx \\ \hline
\end{tabular}}
\end{table}
\end{document}