4

I build a table almost like the table in my picture. But how can I change the color between the stages like in the picture:

This is what i want

\documentclass[a4paper, 12pt,fleqn]{article} 
\usepackage[left=30mm,right=40mm,top=25mm,bottom=20mm, includeheadfoot]  
 {geometry}%centering hinter headfoot
 \usepackage[ngerman]{babel}
 \usepackage[rm={tabular, lining},sf={tabular, lining},tt={monowidth, tabular,       
  lining}]{cfr-lm}
  \usepackage[onehalfspacing]{setspace}     
 \pagestyle{myheadings}
\usepackage{courier}
\renewcommand*\familydefault{\sfdefault} %Schriftart geändert
 \usepackage{booktabs}
\usepackage{hhline}


\begin{document}
  \begin{table}[htbp]
\centering
  \begin{tabular}{cccccccccccc}
   \multicolumn{8}{l}{Datensatz-1 für das Beispielproblem}\\
     \toprule
  & & & & &  \multicolumn{6}{c}{Job}\\
  Stufe & Machsine & & & &  \multicolumn{2}{c}{$n=1$} & & & 
  \multicolumn{3}{c}{$n=2$}\\
  \cmidrule{5-12}
 $i$ & $m$ & 
  $F_{m,i}$ & $R_{m,i}$ & $B_{n,i}$ & $A_{n,i}$ & $D_{n,m,i}$ & 
 $T_{n,m,i}$ & $B_{n,i}$ & $A_{n,i}$ & $D_{n,m,i}$ & $T_{n,m,i}$ \\
 \midrule
   1& & & &1&1& & &1&1& & \\
    &1&0&6& &1&4& & & &1&6 \\
    &2&0&6& &1&4& & & &1&6 \\
   &3&0&6& &1&4& & & &1&6 \\
   2& & & &1&1& & &1&1& & \\
  &1&0&6& & &1&5& & &1&4 \\
  &2&0&6& & &1&5& & &1&4 \\
   3& & & &1&1& & &1&1& & \\
   &1&0&6& & &1&6& & &1&5 \\
  &2&0&6& & &1&6& & &1&5 \\

   \bottomrule
 & & $J_{n}$ & & & \multicolumn{3}{c}{3} & &   \multicolumn{3}{c}{3}\\
 & & $Q_{n}$ & & & \multicolumn{3}{c}{80} & &   \multicolumn{3}{c}{60}\\

\bottomrule  

 \end{tabular}
\label{default}
\end{table} 
\end{document}
5
  • 1
    Possible duplicates: How to create alternating rows in a table?; Table with colored rows alternating every n rows
    – Werner
    Commented Jan 4, 2017 at 21:18
  • @werner those dont help that much :/
    – Milo Li
    Commented Jan 4, 2017 at 21:54
  • The first link shows \rowcolor{<colour>} in the answer. How is that not helpful?
    – Werner
    Commented Jan 4, 2017 at 21:56
  • @Werner it is... but it is switching and i need the first 4 rows grey then 3 white and then 3 grey and unter the line i need no coloring... i dont know how to change it. Now i have a just a switching between grey and white
    – Milo Li
    Commented Jan 4, 2017 at 21:57
  • 1
    Issue \rowcolor{<colour>} for every row you want coloured, even if it is three-in-a-row. For the \midrule and \bottomrule where you want to avoid a white space between the colour, see Professional-looking tables with alternating row colors?
    – Werner
    Commented Jan 4, 2017 at 22:00

2 Answers 2

1

Place \rowcolor{<colour>} in every row that you want the row colour to change. In your case, you'll need a \rowcolor three times to cover the areas.

Since you're using booktabs, see Professional-looking tables with alternating row colors? on how to adjust \midrule and \bottomrule to incorporate some \rowcolor immediately following/preceding it.

Related: How to create alternating rows in a table?

0

In your example, I have replaced {tabular} by {NiceTabular} of nicematrix (with the key color-inside) and I have put four instructions \rowlistcolor{...}. A instruction \rowlistcolors{gray!15} to start a zone of gray rows and an instruction \rowlistcolors{} to stop the coloring.

The output is compatible with the rules of booktabs.

\documentclass[a4paper, 12pt,fleqn]{article} 
\usepackage[left=30mm,right=40mm,top=25mm,bottom=20mm, includeheadfoot] {geometry}
\usepackage[ngerman]{babel}
\usepackage[rm={tabular, lining},sf={tabular, lining},tt={monowidth, tabular, lining}]{cfr-lm}
\usepackage[onehalfspacing]{setspace}     
\pagestyle{myheadings}
\usepackage{courier}
\renewcommand*\familydefault{\sfdefault}
\usepackage{booktabs}

\usepackage{nicematrix}

\begin{document}
  \begin{table}[htbp]
\centering
  \begin{NiceTabular}{cccccccccccc}[color-inside]
   \multicolumn{8}{l}{Datensatz-1 für das Beispielproblem}\\
     \toprule
  & & & & &  \multicolumn{6}{c}{Job}\\
  Stufe & Machsine & & & &  \multicolumn{2}{c}{$n=1$} & & & 
  \multicolumn{3}{c}{$n=2$}\\
  \cmidrule{5-12}
 $i$ & $m$ & 
  $F_{m,i}$ & $R_{m,i}$ & $B_{n,i}$ & $A_{n,i}$ & $D_{n,m,i}$ & 
 $T_{n,m,i}$ & $B_{n,i}$ & $A_{n,i}$ & $D_{n,m,i}$ & $T_{n,m,i}$ \\
 \midrule
 \rowlistcolors{gray!15}
   1& & & &1&1& & &1&1& & \\
    &1&0&6& &1&4& & & &1&6 \\
    &2&0&6& &1&4& & & &1&6 \\
   &3&0&6& &1&4& & & &1&6 \\
 \rowlistcolors{}
   2& & & &1&1& & &1&1& & \\
  &1&0&6& & &1&5& & &1&4 \\
  &2&0&6& & &1&5& & &1&4 \\
 \rowlistcolors{gray!15}
   3& & & &1&1& & &1&1& & \\
   &1&0&6& & &1&6& & &1&5 \\
  &2&0&6& & &1&6& & &1&5 \\
 \bottomrule
 \rowlistcolors{}
 & & $J_{n}$ & & & \multicolumn{3}{c}{3} & &   \multicolumn{3}{c}{3}\\
 & & $Q_{n}$ & & & \multicolumn{3}{c}{80} & &   \multicolumn{3}{c}{60}\\
 \bottomrule  
 \end{NiceTabular}
\label{default}
\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 .