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.
2 Answers
There's the colortbl package, but with \cline
s, 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}
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}
-
Thanks a lot! May I ask, in this case, how do I put all the texts in the middle?– JamesJul 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 changep{1.5cm}
toQ[wd=1.5cm,c]
, etc., for each of the three columns.– frabjousJul 1, 2022 at 20:36 -
-
1Put 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 floatingtable
environment. But it is unclear to me exactly what you mean or want to do.– frabjousJul 1, 2022 at 21:14
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}
MWE
of your code always...