克莱恩不工作

克莱恩不工作

我有这张漂亮的桌子:

\documentclass
\begin{table}[]
\caption [Vyplněná instrukce pro ovládání suction cup]{Vyplněná instrukce pro ovládání suction cup}
\label{tab:sucv}
\catcode`\-=12
\begin{adjustbox}{width=\textwidth}
\begin{tabular}{|
>{\columncolor[HTML]{FFCC67}}c 
>{\columncolor[HTML]{FFCC67}}l |
>{\columncolor[HTML]{98C699}}c |
>{\columncolor[HTML]{DAE8FC}}c 
>{\columncolor[HTML]{DAE8FC}}c 
>{\columncolor[HTML]{DAE8FC}}c 
>{\columncolor[HTML]{DAE8FC}}c 
>{\columncolor[HTML]{DAE8FC}}c 
>{\columncolor[HTML]{DAE8FC}}l |
>{\columncolor[HTML]{E9BCBC}}c |}
\hline
\multicolumn{2}{|c|}{\cellcolor[HTML]{FFCC67}} &
  \cellcolor[HTML]{98C699} &
  \multicolumn{6}{c|}{\cellcolor[HTML]{DAE8FC}Payload} &
  \cellcolor[HTML]{E9BCBC} \\ \cline{4-9}
\multicolumn{2}{|c|}{\cellcolor[HTML]{FFCC67}} &
  \cellcolor[HTML]{98C699} &
  \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}} &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}CTRL} &
  \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}} &
  \cellcolor[HTML]{E9BCBC} \\ \cline{5-6}
\multicolumn{2}{|c|}{\multirow{-3}{*}{\cellcolor[HTML]{FFCC67}Header}} &
  \multirow{-3}{*}{\cellcolor[HTML]{98C699}Len} &
  \multicolumn{1}{c|}{\multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}ID}} &
  \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}RW} &
  \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}isqueued} &
  \multicolumn{3}{c|}{\multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}Params}} &
  \multirow{-3}{*}{\cellcolor[HTML]{E9BCBC}Checksum} \\ \hline
\multicolumn{2}{|c|}{\cellcolor[HTML]{FFCC67}0xAA 0xAA} &
  0x04 &
  \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}0x3E} &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}0x03} &
  \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}0x01} &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}0x01} &
  0xFB \\ \hline
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}

它应该看起来像这样:

看起来应该怎么样

但似乎我的clines没有工作,因为我得到的输出如下所示:

表格中 payload 和 ctrl 下没有线条

“Payload”下没有线,CTRL 下也没有线。

你们对如何解决这个问题有什么建议吗?

答案1

tabularray

\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\usepackage{tabularray}
\makeatletter
\ExplSyntaxOn   %   https://tex.stackexchange.com/questions/629708
\pretocmd{\@declaredcolor}{\my@hack@color{#1}}{}{}
\def\my@hack@color#1{\@ifundefined{\@backslashchar color@#1}{\MyDefineColor{#1}}{\relax}}
\cs_generate_variant:Nn \seq_set_split:Nnn { Nnx }

\NewDocumentCommand \MyDefineColor { m } {
  \seq_set_split:Nnx \l_tmpa_seq {|} {#1}
  %\seq_show:N \l_tmpa_seq
  \exp_args:Nnxx \definecolor{#1} { \seq_item:Nn \l_tmpa_seq {1} } { \seq_item:Nn \l_tmpa_seq {2} }
}
\ExplSyntaxOff
\makeatother

\begin{document}
    \begin{table}[ht]
\caption[Vyplněná instrukce pro ovládání suction cup]
        {Vyplněná instrukce pro ovládání suction cup}
\label{tab:sucv}
\begin{tblr}{hlines, vlines,
             colspec = {*{2}{Q[c, bg={HTML|FFCC67}]}
                             Q[c, bg={HTML|98C699}]
                        *{5}{Q[c, bg={HTML|DAE8FC}]}
                             Q[c, bg={HTML|DAE8BC}]},
             }
\SetCell[c=2,r=3]{c}    Heaser
        &       &   \SetCell[r=3]{c}    Len
                        &   \SetCell[c=5]{c}  Payload
                                &           &       &       &       &   \SetCell[r=3]{c}    Checksumm   \\
        &       &       &   \SetCell[r=2]{c}    ID
                                & \SetCell[c=2]{c}  CTRL
                                            &       &   \SetCell[c=2, r=2]{c}    Params
                                                            &       &       \\
        &       &       & ID    & RW        & isqueued  
                                                    &       &       &       \\

0xAA    & 0xAA  & 0x04  & 0xe49 &  \SetCell[c=2]{c}    0x03
                                            &       & 0x00  & 0x01  & 0xb6  \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

或者使用预定义的颜色:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
    \begin{table}[ht]
\caption[Vyplněná instrukce pro ovládání suction cup]
        {Vyplněná instrukce pro ovládání suction cup}
\label{tab:sucv}
\begin{tblr}{hlines, vlines,
             colspec = {*{2}{Q[c, bg=orange!30]}
                             Q[c, bg=green!30]
                        *{5}{Q[c, bg=cyan!30]}
                             Q[c, bg=olive!30]},
             }
\SetCell[c=2,r=3]{c}    Heaser
        &       &   \SetCell[r=3]{c}    Len
                        &   \SetCell[c=5]{c}  Payload
                                &           &       &       &       &   \SetCell[r=3]{c}    Checksumm   \\
        &       &       &   \SetCell[r=2]{c}    ID
                                & \SetCell[c=2]{c}  CTRL
                                            &       &   \SetCell[c=2, r=2]{c}    Params
                                                            &       &       \\
        &       &       & ID    & RW        & isqueued  
                                                    &       &       &       \\

0xAA    & 0xAA  & 0x04  & 0xe49 &  \SetCell[c=2]{c}    0x03
                                            &       & 0x00  & 0x01  & 0xb6  \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

答案2

生成的线\cline被单元格的颜色覆盖。这就是它不可见的原因。一个解决方案可能是使用包hhline,这需要对行高进行小幅调整,否则多行单元格中会显示间隙。我调整了您的表格并简化了代码:

\documentclass[border=10pt]{standalone}
\usepackage{colortbl, xcolor, multirow, hhline}
\begin{document}
\begin{tabular}{|
>{\columncolor[HTML]{FFCC67}}c|
>{\columncolor[HTML]{FFCC67}}c|
>{\columncolor[HTML]{98C699}}c|
>{\columncolor[HTML]{DAE8FC}}c|
>{\columncolor[HTML]{DAE8FC}}c|
>{\columncolor[HTML]{DAE8FC}}c|
>{\columncolor[HTML]{DAE8FC}}c|
>{\columncolor[HTML]{DAE8FC}}c|
>{\columncolor[HTML]{E9BCBC}}c|}
\hline
\multicolumn{2}{|c|}{\cellcolor[HTML]{FFCC67}} &
  \cellcolor[HTML]{98C699} &
  \multicolumn{5}{c|}{\cellcolor[HTML]{DAE8FC}Payload} &
  \cellcolor[HTML]{E9BCBC} \\[-.4pt] 
\hhline{~~~-----~}
\multicolumn{2}{|c|}{\cellcolor[HTML]{FFCC67}} &
  \cellcolor[HTML]{98C699} &
  \cellcolor[HTML]{DAE8FC} &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}CTRL} &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}} &
  \cellcolor[HTML]{E9BCBC} \\[-.4pt] 
\hhline{~~~~--~~~}
\multicolumn{2}{|c|}{\multirow{-3}{*}{\cellcolor[HTML]{FFCC67}Header}} &
  \multirow{-3}{*}{\cellcolor[HTML]{98C699}Len} &
  \multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}ID} &
  \cellcolor[HTML]{DAE8FC}RW &
  \cellcolor[HTML]{DAE8FC}isqueued &
  \multicolumn{2}{c|}{\multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}Params}} &
  \multirow{-3}{*}{\cellcolor[HTML]{E9BCBC}Checksum} \\ 
\hline
\multicolumn{1}{|c|}{\cellcolor[HTML]{FFCC67}0xAA} &
  0xAA & 
  0x04 &
  \cellcolor[HTML]{DAE8FC}0x3E &
  \multicolumn{2}{c|}{\cellcolor[HTML]{DAE8FC}0x03} &
  \cellcolor[HTML]{DAE8FC}0x01 &
  \cellcolor[HTML]{DAE8FC}0x01 &
  0xFB \\ 
\hline
\end{tabular}
\end{document}

在此处输入图片描述

答案3

与。{NiceTabular}nicematrix

\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{nicematrix}
\usepackage{caption}

\begin{document}
\begin{table}[ht]
\centering
\caption[Vyplněná instrukce pro ovládání suction cup]
        {Vyplněná instrukce pro ovládání suction cup}
\label{tab:sucv}

\begin{NiceTabular}[hvlines,cell-space-limits=2pt]{ccccccccc}
\CodeBefore
  \columncolor{orange!30}{1,2}
  \columncolor{green!30}{3}
  \columncolor{cyan!30}{4-8}
  \columncolor{olive!30}{9}
\Body
\Block{3-2}{Heaser}
        &       &   \Block{3-1}{Len}
                        &   \Block{1-5} {Payload}
                                &           &       &       &       &   \Block{3-1}{Checksumm}   \\
        &       &       &   \Block{2-1}{ID}
                                & \Block{1-2}{CTRL}
                                            &       &  \Block{2-2}{Params}
                                                            &       &       \\
        &       &       &      & RW        & isqueued  
                                                    &       &       &       \\

0xAA    & 0xAA  & 0x04  & 0xe49 &  \Block{1-2}{0x03}
                                            &       & 0x00  & 0x01  & 0xb6  \\
\end{NiceTabular}
\end{table}
\end{document}

上述代码的输出

相关内容