0

I have this beautiful table:

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

it should look like this:

how it should look

but it seems like my clines are not working, because the output I get looks like this:

table without lines under payload and ctrl

There is no line under "Payload" and no line under CTRL.

Do you guys have any tip on how to solve this?

4

3 Answers 3

5

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

enter image description here

or by use of predefined colors:

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

enter image description here

3

The line generated with \cline is covered by the color of the cell. This is why it is not visible. A solution could be to use the hhline package, which would require a small adjustment in the row height because otherwise a gap would show in multirow cells. I adjusted your table and simplified the code a bit:

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

enter image description here

2

With {NiceTabular} of 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}

Output of the above code

You must log in to answer this question.

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