\hspace 搞乱了过度支撑

\hspace 搞乱了过度支撑

我想修复不正确的过度支撑,并将“ADD”放在数组上方,但没有垂直分隔符,也许会稍微多一点,用一条小线指向数组的第一个元素。对不起,我是个菜鸟,我第一次使用 latex 写大学报告。这是我的代码:

\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}```

答案1

目前尚不清楚您想要什么,但它可能是类似以下内容的东西。

  1. 仅一个tabular环境
  2. 列具有固定宽度
  3. 过度支撑仅延伸到“ADD”之后的列;由于列的宽度是固定的,因此可以知道过度支撑应该有多长。
  4. 我进行了调整\tabcolsep,以便表格可以包含在设置的边距中geometry;您可以根据您的设置调整该长度。
\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}

在此处输入图片描述

相关内容