3

I want to generate a table as shown below

enter image description here

I have tried to design it. The problems are

  1. In 1st column, I am unable to centre align the text aaa. Similarly, for the second column.
  2. I am unable to keep the colour of 1st column same.
  3. I am unable to centring the text "Restrictions" in the 1st row.

How can I proceed to address this matter? I would appreciate your assistance in resolving this.

 \documentclass{article}
    \usepackage{geometry}
    \usepackage{tabularray}
    \UseTblrLibrary{booktabs}
    \usepackage{multirow,float}
     \usepackage[table,xcdraw]{xcolor}
    \usepackage{xcolor}
    \definecolor{ultramarine}{RGB}{0,32,96}
    \definecolor{lightb}{RGB}{217,224,250}
        \usepackage{amsmath}
    \begin{document}
      \begin{table}[H]
    \begin{tabular}{lllll}
    \hline
    \rowcolor{teal2}
    \multicolumn{4}{l}{\bf \color{white} \centering Restrictions}                                                     & \bf \color{white} Remarks \\ 
    \hline
    \rowcolor{cyan!30}
    \multicolumn{1}{l}{$aaa$}                   & \multicolumn{1}{l}{bbb}                   & \multicolumn{1}{l}{ccc} & ddd & eee        \\ 
    %\cline{3-5} 
    \rowcolor{gray!20}
    \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{56} & 78 & 910        \\ %\cline{3-5} 
    \rowcolor{cyan!30}
    \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{\multirow{-3}{*}{}} & \multicolumn{1}{l}{cd} & ef & gh        \\
    %\cline{2-5} 
    \rowcolor{gray!20}
    \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{z1}                   & \multicolumn{1}{l}{z2} & z3 &  z4       \\ 
    %\cline{3-5} 
    \rowcolor{cyan!30}
    \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{z5} & z6 &  z7       \\ 
    %\cline{3-5} 
    \rowcolor{gray!20}
    \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{\multirow{-3}{*}{}} & \multicolumn{1}
{l}{z8} & z9 &   z10      \\ %\cline{2-5} 
\rowcolor{cyan!30}
\multicolumn{1}{l}{}                   & \multicolumn{1}{l}{1a}                   & \multicolumn{1}{l}{1b} & 1c &  1d       \\ 
%\cline{3-5} 
\rowcolor{gray!20}
\multicolumn{1}{l}{}                   & \multicolumn{1}{l}{}                   & \multicolumn{1}{l}{2a} & 2b &   2c      \\ 
%\cline{3-5} 
\rowcolor{cyan!30}
\multicolumn{1}{l}{\multirow{-9}{*}{}} & \multicolumn{1}{l}{\multirow{-3}{*}{}} & \multicolumn{1}{l}{3a} & 3b &  3c       \\ \hline
\end{tabular}
\end{table}
 \end{document}

The above code generates the following table

enter image description here

3
  • You are using deprectated font switchs (\bf should be \bfseries). Be aware of that. Also you are loading a lot of table packages yet tabularray is more than enough to typeset this table.
    – Mane32
    Feb 25 at 6:58
  • for generating structures of complicated tables like this you can use latex-tables.com . combining/splitting cells is very easily done.
    – Damitr
    Feb 25 at 7:06
  • Maybe have a look at texdoc.org/serve/booktabs.pdf/0 which has some information on how to design professional looking tables Feb 25 at 11:31

2 Answers 2

6

You are loading tabularray package yet you are not using it at all.

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
    \begin{table}
    \centering
    \begin{tblr}{
    % Specify 5 columns, *{5}{X} is valid also.
    colspec = XXXXX,
    % Sets the width of the table
    width=\linewidth,
    % Sets the style of the 1st row
    row{1} = {c,font=\sffamily\bfseries,bg=azure5,fg=white},
    % Sets horizontal and vertical lines color, style and width
    hlines = {azure5,solid,0.4pt},
    vlines = {azure5,solid,0.4pt},
    % cell from row 1 and column 1 must extend 3 columns and be centered
    cell{1}{1} = {c=3,r=1}{c},
    % cell from row 1 and column 4 must extend 2 columns and be centered
    cell{1}{4} = {c=2,r=1}{c},
    % cell from row 2 and column 1 must extend 9 rows and be centered
    cell{2}{1} = {c=1,r=9}{c},
    % cell from rows 2,5,8 and column 2 must extend 1 column and 3 rows, and be centered.
    cell{2,5,8}{2} = {c=1,r=3}{c},
    % The following line sets all even rows background
    row{even} = {bg=azure9},
    }
    %% Here comes the real table
    Restrictions &      &     & Remarks &       \\
            aaa  & bbb  & ccc & ddd     & eee   \\
                 &      & 56  & 78      & 910   \\
                 &      & cd  & ef      & gh    \\
                 & z1   & z2  & z3      & z4    \\
                 &      & z5  & z6      & z7    \\
                 &      & z8  & z9      & z10   \\
                 & 1a   & 1b  & 1c      & 1d    \\
                 &      & 2a  & 2b      & 2c    \\
                 &      & 3a  & 3b      & 3c    \\
    \end{tblr}
    \end{table}
\end{document}

The output should be like this:

table output

3
  • @Mane22 Excellent!!! Thanks a lot. If I want to change both even and odd row colours by using row{even} = {bg=cyan!30}, row{odd} = {bg=gray!20} keeping the 1st row bg=azure5,fg=white, I am not getting the desired. The 1st row bg colour is also changing. What to do for this? Feb 25 at 7:10
  • 1
    Put the specification of row{odd} before row{1} specification to avoid overwriting it (1 is also odd so row{odd} overwrites it). Also, if this solves your problem, you can mark my answer as accepted answer.
    – Mane32
    Feb 25 at 8:56
  • thank you ..... Feb 25 at 9:11
3

Here is a solution with {NiceTabular} of nicematrix. You need several compilations.

\documentclass{article}
\usepackage{ninecolors}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\begin{NiceTabular}[hvlines,rules/color=azure5]{XXX[l]X[l]X[l]}
\CodeBefore
 \rowcolors{1}{}{azure9}[cols={3,4,5}]  
\Body
 \RowStyle[rowcolor=azure5,color=white]{\sffamily\bfseries}
 \Block{1-3}{Restrictions} 
              &      &     & \Block{1-2}{Remarks} \\
 \Block[fill=azure9]{*-1}{aaa}  
              & \Block[fill=azure9]{3-1}{bbb}  
                     & ccc & ddd     & eee   \\
              &      & 56  & 78      & 910   \\
              &      & cd  & ef      & gh    \\
              & \Block{3-1}{z1}   
                     & z2  & z3      & z4    \\
              &      & z5  & z6      & z7    \\
              &      & z8  & z9      & z10   \\
              & \Block[fill=azure9]{3-1}{1a}   
                     & 1b  & 1c      & 1d    \\
              &      & 2a  & 2b      & 2c    \\
              &      & 3a  & 3b      & 3c    \\
\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 .