3

I would to import the following table in latex with color, how do I make it possible? Many thanks in advance! The colors don't have to be exactly the same. enter image description here

2
  • 1
    It's weird in your sample that the Step 4 cell in the first column is shorter than the Step 5 cell, but it's the reverse in the third column. I assume that's not intended.
    – frabjous
    Jul 1, 2022 at 15:09
  • 1
    Please keep MWE of your code always...
    – MadyYuvi
    Jul 1, 2022 at 15:25

2 Answers 2

6

There's the colortbl package, but with \clines, I recommend either the NiceTabular environment from the nicematrix package, or using the similar facilities of the tabularray package.

With nicematrix:

\documentclass{article}

% for color models
\usepackage{xcolor}

% for nice coloring in tables
\usepackage{nicematrix}

% for multi-row cells
\usepackage{multirow}

%for Helvetica-like sans font
\usepackage[T1]{fontenc}
\usepackage{tgheros}

\begin{document}

\sffamily

% adds some vertical padding in cells
\renewcommand{\arraystretch}{1.5}

% slightly thicker lines
\setlength{\arrayrulewidth}{0.8pt}

\begin{NiceTabular}{|p{1.5cm}|p{1.5cm}|p{6cm}|}[colortbl-like]
\hline
\rowcolor{yellow} Step 1 & 1 & xx \\
\hline
\rowcolor[HTML]{d4f0dc} Step 2 & 2 & xx \\
\hline
\rowcolor[HTML]{b7e0ff} Step 3 & \multirow{4}*{3} & xx\\
\cline{1-1}\cline{3-3}
\rowcolor[HTML]{b7e0ff} Step 4 & & xx \\
\cline{1-1}\cline{3-3}
\rowcolor[HTML]{b7e0ff}Step 5 & & xx\\
\cline{1-1}\cline{3-3}
\rowcolor[HTML]{b7e0ff}Step 6 & & xx\\
\hline
\rowcolor[HTML]{92d050} Step 7 & 1 & xx\\
\hline
\end{NiceTabular}

\end{document}

nicetabular output

With the tabularray package (exactly similar output):

\documentclass{article}

% for color models
\usepackage{xcolor}

% for nice coloring in tables
\usepackage{tabularray}

% for multi-row cells
\usepackage{multirow}

%for Helvetica-like sans font
\usepackage[T1]{fontenc}
\usepackage{tgheros}

\begin{document}

\sffamily

% adds some vertical padding in cells
\renewcommand{\arraystretch}{1.5}

% slightly thicker lines
\setlength{\rulewidth}{0.8pt}

% define colors
\definecolor{mycyan}{HTML}{d4f0dc}
\definecolor{myblue}{HTML}{b7e0ff}
\definecolor{mygreen}{HTML}{92d050}
\begin{tblr}{
    colspec={|p{1.5cm}|p{1.5cm}|p{6cm}|},
}
\hline
\SetRow{yellow}
Step 1 & 1 & xx \\
\hline
\SetRow{mycyan}
Step 2 & 2 & xx \\
\hline
\SetRow{myblue}
Step 3 & \SetCell[r=4]{wd=1.5cm}{3} & xx\\
\cline{1-1}\cline{3-3}
\SetRow{myblue}
Step 4 & & xx \\
\cline{1-1}\cline{3-3}
\SetRow{myblue}
Step 5 & & xx\\
\cline{1-1}\cline{3-3}
\SetRow{myblue}
Step 6 & & xx\\
\hline
\SetRow{mygreen}
Step 7 & 1 & xx\\
\hline
\end{tblr}

\end{document}
4
  • Thanks a lot! May I ask, in this case, how do I put all the texts in the middle?
    – James
    Jul 1, 2022 at 20:26
  • I'm not sure what you mean. Do you mean horizontally center the contents? In the first solution, if you wanted to keep the widths, in the colspec, you could change p{1.5cm} to >{\centering\arraybackslash}p{1.5cm} (for each of the three columns). (Or just use 'c' if you don't want to keep the manual widths.) In the second solution change p{1.5cm} to Q[wd=1.5cm,c], etc., for each of the three columns.
    – frabjous
    Jul 1, 2022 at 20:36
  • Thanks a lot, how to put the whole table in the middle of the paper?
    – James
    Jul 1, 2022 at 20:46
  • 1
    Put the part of the paper you want before it, before it (after \begin{document}) and the part of the paper you want after it, after it (before \end{document})? You could put \begingroup before \sffamily and put \endgroup after \end{NiceTabular} or \end{tblr} if you don't want the rest in sans serif. You could also consider putting it in a floating table environment. But it is unclear to me exactly what you mean or want to do.
    – frabjous
    Jul 1, 2022 at 21:14
4

frabjous has provided a solution with nicematrix. For information, here is a way a bit shorter to create that tabular with nicematrix.

\documentclass{article}

% for color models
\usepackage{xcolor}
\definecolor{mycyan}{HTML}{b7e0ff}

% for nice coloring in tables
\usepackage{nicematrix}

%for Helvetica-like sans font
\usepackage[T1]{fontenc}
\usepackage{tgheros}

\begin{document}

\sffamily

% adds some vertical padding in cells
\renewcommand{\arraystretch}{1.5}

% slightly thicker lines
\setlength{\arrayrulewidth}{0.8pt}

\begin{NiceTabular}{p{1.5cm}p{1.5cm}p{6cm}}[colortbl-like,hvlines]
\rowcolor{yellow} Step 1 & 1 & xx \\
\rowcolor[HTML]{d4f0dc} Step 2 & 2 & xx \\
\RowStyle[nb-rows=4,rowcolor=mycyan]{} 
                        Step 3 & \Block[l]{4-1}{3} & xx\\
                        Step 4 &   & xx \\
                        Step 5 &   & xx \\
                        Step 6 &   & xx \\                       
\rowcolor[HTML]{92d050} Step 7 & 1 & xx\\
\end{NiceTabular}

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