9

I would like to reproduce these kinds of arrays in Latex (probably with tcolorbox) but I have no idea how to achieve this. So is there a way to make these kinds of tables ?

enter image description here

Note : I would like the switching between colors from one line to another to be automatic.

jub0bs
  • 58,916
Vincent
  • 5,257
  • 1
    I think with colortbl is enough, there's no need for tcolorbox unless you want to add frames. Some examples here: http://tex.stackexchange.com/questions/112343/beautiful-table-samples?lq=1, http://tex.stackexchange.com/questions/94032/fancy-tables-in-latex?rq=1 – Ignasi May 09 '14 at 07:31
  • With colortbl it can be made automatic. –  May 09 '14 at 07:35
  • 2
    See also these slides on how to make good tables: https://speakerdeck.com/cherdarchuk/clear-off-the-table – Henri Menke May 09 '14 at 08:39
  • Here is the gif version http://darkhorseanalytics.com/blog/wp-content/uploads/2014/03/ClearOffTheTableMd.gif – Trefex May 09 '14 at 09:40

2 Answers2

7

The colortbl package is enough to create such tables as the other commentors wrote. The following example code uses \usepackage[svgnames,table]{xcolor} where the option table loads colortbl:

\documentclass[a4paper,12pt]{article}
\usepackage[left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm,ignoreheadfoot]{geometry}
\usepackage{array}
\usepackage[svgnames,table]{xcolor}

\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{blue!50!white}}c}
\newcolumntype{B}{>{\columncolor{LightGoldenrod}}c}
\newcolumntype{C}{>{\columncolor{FireBrick!50}}c}
\newcolumntype{D}{>{\columncolor{Gray!42}}c}

\begin{document}    

\begin{center}
\sffamily
\arrayrulecolor{white}
\arrayrulewidth=1pt
\renewcommand{\arraystretch}{1.5}
\rowcolors[\hline]{3}{.!50!White}{}
\begin{tabular}{A|B|C}
  \multicolumn{3}{D}{\bfseries Example table}\\
  \rowcolor{.!50!Black}
  \arraycolor{White}\bfseries First column &
  \arraycolor{White}\bfseries Second column&
  \arraycolor{White}\bfseries Third column\\
  1 & A & E\\
  2 & B & F\\
  3 & C & G\\
  4 & D & H\\
\end{tabular}
\end{center}

\end{document}

enter image description here

5

With {NiceTabular} of nicematrix which has built-in tools for the colorful tables.

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

\begin{document}

\sffamily \renewcommand{\arraystretch}{1.4}

\begin{center} \begin{NiceTabular} [ columns-width=3cm, hvlines-except-borders, rules={color=white,width=1pt} ] {ccc} \CodeBefore \rowcolor{cyan}{1} \rowcolors{2}{cyan!25}{cyan!15} \Body \RowStyle[color=white]{} First column & Second column & Third column \ 1 & A & E \ 2 & B & F \ 3 & C & G \ 4 & D & H \ \end{NiceTabular} \end{center}

\vspace{5mm} \begin{center} \begin{NiceTabular}[corners=NW,hvlines]{ccc} \CodeBefore \rowcolor{cyan}{1} \columncolor{cyan}{1} \rowcolors{2}{cyan!25}{cyan!15}[cols={2,3}] \Body & First column & Second column \ First line & A & E \ Second line & B & F \ Third line & C & G \ Fourth line & D & H \ \end{NiceTabular} \end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250