\hspace 搞亂了大括號

\hspace 搞亂了大括號

我想修復不正確的大括號,並將“ADD”放在數組上,但沒有垂直分隔符,也許用一條小線指向數組的第一個元素。抱歉,我是菜鳥,我第一次使用乳膠做大學報告。這是我的程式碼:

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

在此輸入影像描述

相關內容