4

I want to add a annotation below of a (colored) table-column.
But this changes the column-with.

As a try, I put the annotation in a parbox. This works, but then the annotation is no longer nicely symmetrically placed.

Is it possible to "overlay" stuff in a normal table?
(There are certainly solutions using TikZ, nicematrix etc. But I would like to understand how to do this using normal table tools.)

enter image description here

\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
  • 1
    Use \clap{} inside those macros, e.g. \def\da{\clap{$\overbrace{2}^{\text{above}}$}}. The content of \clap does not take any space but is still rendered. This way column width should remains the same.
    – Celdor
    Apr 2 at 10:32

2 Answers 2

6

Without additional packages, with false with of \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}

enter image description here

2
  • 1
    Is it \Is or \It? +1
    – Sebastiano
    Apr 2 at 11:48
  • 1
    @Sebastiano Thank you! Corrected. The first line is not a place where we are expecting mistakes. :-) Apr 2 at 11:58
5

The mathtools define commands to squeeze the width: \mathllap (left aligned), \mathclap (centered) and \mathrlap (right aligned).

Here, use \mathclap

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

and add \usepackage{mathtools}.

mathclap solution

1
  • \clap as suggested by @Celdor is even simpler and doesn't need another package.
    – jlab
    Apr 2 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .