在不改变列宽的情况下向表添加注释

在不改变列宽的情况下向表添加注释

我想在(彩色)表格列下方添加注释。
但这会改变列。

作为一个尝试,我将注释放在了 中parbox。这有效,但是注释不再很好地对称放置。

是否有可能在普通表
(当然有使用 TikZ、nicematrix 等的解决方案。但我想了解如何使用普通表格工具来做到这一点。)

在此处输入图片描述

\documentclass[]{article}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{amsmath}
\begin{document}

\setlength\arrayrulewidth{0.8125pt} % seems to be needed...
\setlength\tabcolsep{1pt}% seems to be needed...

\newcolumntype{P}{>{\centering\arraybackslash}p{3mm}}
\newcolumntype{Q}{>{\columncolor{purple!33}}P}

\def\x{$\scriptstyle\times$}
\def\da{$\downarrow$\rule{0pt}{1em}}

\def\Is{$\overbrace{2}^{\text{above}}$}

\section{Without annotation -- last column size good}
\begin{tabular}{| P | P | Q |}
      \multicolumn{1}{c}{1.}  
         & \multicolumn{1}{c}{2.}  
              &  \multicolumn{1}{c}{3.}  \\ \hline
 & &   \\  \hline % Problem here
 & &   \\ \hline
 & &        \cellcolor{red}\x \\ \hline
 & &  \\ \hline
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\da}  \\
\end{tabular}


\section{With annotation -- last column size bad}
\begin{tabular}{| P | P | Q |}
      \multicolumn{1}{c}{1.}  
         & \multicolumn{1}{c}{2.}  
              &  \multicolumn{1}{c}{3.}  \\ \hline
 & &   \\  \hline % Problem here
 & &   \\ \hline
 & &        \cellcolor{red}\x \\ \hline
 & &  \\ \hline
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\da}  \\
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\Is}  
\end{tabular}

\end{document}

答案1

无需附加软件包,使用 false 的\Is

\documentclass[]{article}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{amsmath}
\begin{document}

\setlength\arrayrulewidth{0.8125pt} % seems to be needed...
\setlength\tabcolsep{1pt}% seems to be needed...

\newcolumntype{P}{>{\centering\arraybackslash}p{3mm}}
\newcolumntype{Q}{>{\columncolor{purple!33}}P}

\def\x{$\scriptstyle\times$}
\def\da{$\downarrow$\rule{0pt}{1em}}

%\def\Is{$\overbrace{2}^{\text{above}}$}
\def\Is{\makebox[0pt]{$\overbrace{2}^{\text{above}}$}}

\section{Without annotation -- last column size good}
\begin{tabular}{| P | P | Q |}
      \multicolumn{1}{c}{1.}  
         & \multicolumn{1}{c}{2.}  
              &  \multicolumn{1}{c}{3.}  \\ \hline
 & &   \\  \hline % Problem here
 & &   \\ \hline
 & &        \cellcolor{red}\x \\ \hline
 & &  \\ \hline
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\da}  \\
\end{tabular}


\section{With annotation -- last column size bad}
\begin{tabular}{| P | P | Q |}
      \multicolumn{1}{c}{1.}  
         & \multicolumn{1}{c}{2.}  
              &  \multicolumn{1}{c}{3.}  \\ \hline
 & &   \\  \hline % Problem here
 & &   \\ \hline
 & &        \cellcolor{red}\x \\ \hline
 & &  \\ \hline
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\da}  \\
%
      \multicolumn{1}{c}{}
         & \multicolumn{1}{c}{}
              &  \multicolumn{1}{c}{\Is}  % <- here
\end{tabular}

\end{document}

在此处输入图片描述

答案2

数学工具定义挤压宽度的命令:(\mathllap左对齐)、\mathclap(居中)和\mathrlap(右对齐)。

在这里,使用\mathclap

\def\Is{$\mathclap{\overbrace{2}^{\text{above}}}$}

并添加\usepackage{mathtools}

mathclap 解决方案

相关内容