\hspace estropea el overbrace

\hspace estropea el overbrace

Me gustaría arreglar el soporte incorrecto y también colocar "AGREGAR" sobre la matriz pero sin el divisor vertical, tal vez colocándolo un poco por encima con una pequeña línea que apunta al primer elemento de la matriz. Lo siento, soy un novato y estoy usando látex para un informe universitario por primera vez. Este es mi código:

\setbox0=\hbox{$
    \arrayrulecolor{black} % Color for table borders
    \rowcolors{1}{white}{gray!30} % Alternate gray backgrounds in rows
    \hspace{-2em}\begin{array}{|c|*{27}{c|}}
    ADD   \\
    \hline
    \textbf{128} & \hphantom{0}0 &
    \textbf{64} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}}  & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}}& \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textbf{100} & \hphantom{0}0 &
    \textbf{1} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{0}} & \hphantom{0}0  &
    \textbf{5} &  \hphantom{0}0 \\
    \hline
    \end{array}
$}

% Underbrace without left bracket
\[
  \overbrace{\usebox0}^{K}
\]



\begin{center}
    % Draw a down-facing arrow from "ADD" to the first element
    \begin{tikzpicture}
    % Downward arrow pointing from "ADD" to the first element
    \draw[->, thick] (0, 1.5) -- (0, 0.5); % Draw the down arrow
    \end{tikzpicture}
    \end{center}

    \vspace{-2.5em} % Negative space to bring elements closer
    
    \begin{center}
\[ 
    \arrayrulecolor{black} % Color for table borders
    \rowcolors{1}{gray!30}{gray!30} % Alternate gray backgrounds in rows
    \hspace{-2em}\begin{array}{|c|*{27}{c|}}
        \hline
    \hphantom{0}\textbf{128}\hphantom{0} & \textcolor{red}{31} &
    \textbf{64}& \textcolor{red}{31}&
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{30}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{29}&
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{28}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{27}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{26}& 
    \textbf{100}& \textcolor{red}{31}& 
    \textbf{1}& \textcolor{red}{31}& 
    \textcolor{blue}{\textbf{1}}& \textcolor{red}{30}& 
    \textbf{5}& \textcolor{red}{31} \\
    \hline
    
    \end{array} 
\]
\end{center}```

Respuesta1

No está muy claro lo que quieres, pero podría ser algo como lo que sigue.

  1. Solo un tabularambiente
  2. Las columnas tienen ancho fijo.
  3. El refuerzo sólo se extiende sobre las columnas después de "AÑADIR"; Dado que las columnas tienen un ancho fijo, es posible saber cuánto tiempo debe tener el refuerzo.
  4. Lo ajusté \tabcolseppara que la tabla pueda estar contenida en los márgenes según lo establecido por geometry; Dependiendo de tu configuración, puedes jugar con esa duración.
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage{amsmath}

\newlength{\lenA}
\newlength{\lenB}

\begin{document}

\begin{center}
\small
\settowidth{\lenA}{ADD}
\settowidth{\lenB}{\textbf{00}}
\setlength{\tabcolsep}{3.7pt}

  \begin{tabular}{|w{c}{\lenA}|*{21}{w{c}{\lenB}|}}
    \multicolumn{1}{c}{\textrm{ADD}} &
    \multicolumn{1}{l}{\makebox[0pt][l]{%
      $\overbrace{\hspace{\dimeval{21\lenB+40\tabcolsep+20\arrayrulewidth}}}^K$%
    }}
   \\
    \hline
    \rowcolor{gray!30}% Alternate gray backgrounds in rows
    \textbf{128} & \hphantom{0}0 &
    \textbf{64} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{\hphantom{0}0}} & \hphantom{0}0 &
    \textbf{100} & \hphantom{0}0 &
    \textbf{1} & \hphantom{0}0 &
    \textcolor{blue}{\textbf{0}} & \hphantom{0}0  &
    \textbf{5} &  \hphantom{0}0 \\
    \hline
    \multicolumn{1}{c}{} \\[-1.5ex]
    \multicolumn{1}{c}{$\left\downarrow\vbox to 15pt{}\right.$} \\
    \multicolumn{1}{c}{} \\[-1.5ex]
    \hline
    \rowcolor{gray!30} % Alternate gray backgrounds in rows
    \textbf{128} & \textcolor{red}{31} &
    \textbf{64}& \textcolor{red}{31}&
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{30}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{29}&
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{28}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{27}& 
    \textcolor{blue}{\textbf{64}}& \textcolor{red}{26}& 
    \textbf{100}& \textcolor{red}{31}& 
    \textbf{1}& \textcolor{red}{31}& 
    \textcolor{blue}{\textbf{1}}& \textcolor{red}{30}& 
    \textbf{5}& \textcolor{red}{31} \\
    \hline
  \end{tabular}
\end{center}

\end{document}

ingrese la descripción de la imagen aquí

información relacionada