0

I want to draw a table using threepartable. I want the following structure: 1- the first line includes 2 rows:\multirow 2- the second line includes also two rows 3-the third line include 3 rows 4- fourth row includes 1 5- 5th includes 5 rows 6- 6th includes 6 rows.

My question: how can alternate the color in the table?

This is an example including the first three rows

    \begin{table}
\caption{table.}\label{}
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
%\resizebox{\textwidth}{!}{
\begin{tabular}{lccccc}
    \headrow
    \textbf{Approach}& \textbf{X}& \textbf{Y}& \textbf{Z}&\textbf{W}&\textbf{O}\\ 
    
    \multirow{2}{*}{ligne 1} 
    &\multirow{2}{*}{\shortstack[m]{BL BLA\\ bla}}
    & \multirow{2}{*}{aa} 
    &\multirow{2}{*}{bb}
    &\multirow{2}{*}{cc}
    &\multirow{2}{*}{dd} \\\rowcolor{Gray}
    
    
    \multirow{2}{*}{line2} 
    &\multirow{2}{*}{\shortstack[m]{BL BLA\\ blq}}
    & \multirow{2}{*}{aa2} 
    &\multirow{2}{*}{bb2}
    &\multirow{2}{*}{cc2}
    &\multirow{2}{*}{dd2} \\
    
    \multirow{3}{*}{ligne3} 
    &\multirow{3}{*}{\shortstack[m]{bla\\ bla}}
    & \multirow{3}{*}{aa3} 
    &\multirow{3}{*}{bb3}
    &\multirow{3}{*}{\shortstack[m]{ccc3\\ ccc3\\ccc3}}
    &\multirow{3}{*}{ddd3}\\\rowcolor{Gray}
    
      
    \end{tabular}
\end{threeparttable}
\end{adjustbox}
\end{table}

By default, the header of the table is dark gray. I need the line 1 to be white, then line 2 gray, line 3 white, etc

6
  • 1
    How the table itself looks like is not very clear to me. Could you post a compilable (complete) code?
    – Bernard
    Sep 11, 2020 at 8:29
  • 1
    A minimal working example showing such a table without the colors, as well as a sketch that illustrates which rows should have which color would be really helpful here. Could you please add this information to your question?
    – leandriis
    Sep 11, 2020 at 8:31
  • Please make your example code compilable by adding the documentclass as well as the relevant packages. How is the \headrow command defined?
    – leandriis
    Sep 11, 2020 at 9:05
  • Is this the output you want to achieve? i.stack.imgur.com/HfniC.png If so, take a look at the \rowcolors command from the xcolor package (when loaded with the tables option) and the makecell package instead of the combination of \shortstack and \multirow.
    – leandriis
    Sep 11, 2020 at 9:13
  • Please post MWE from \documentclass to \end{document}...
    – MadyYuvi
    Sep 11, 2020 at 12:36

1 Answer 1

0

With the help of makecell from the makecell package instead of the combination of \multirow and \shortstack. In order to add the alternating row colors, I have used the \rowcolors command, that is available when loading the xcolor package with the tables option:

enter image description here

\documentclass{article}
\usepackage[table,svgnames]{xcolor}
\usepackage{makecell}
\usepackage{threeparttable}
\begin{document}

\begin{table}
\caption{table.}\label{}
\rowcolors{1}{lightgray}{white}
\begin{threeparttable}
\begin{tabular}{lccccc}
    \textbf{Approach}& \textbf{X}& \textbf{Y}& \textbf{Z}&\textbf{W}&\textbf{O}\\ 
    
     ligne 1 
    &\makecell{BL BLA\\ bla}
    &aa 
    &bb
    &cc
    &dd \\  
    
     line2 
    &\makecell{BL BLA\\ blq}
    &aa2 
    &bb2
    &cc2
    &dd2 \\
    
     ligne3 
    &\makecell{bla\\ bla}
    &aa3
    &bb3
    &\makecell{ccc3\\ ccc3\\ccc3}
    &ddd3\\
      
    \end{tabular}
\end{threeparttable}
\end{table}

\end{document}

You must log in to answer this question.

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