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}
Werner
  • 603,163
Milo Li
  • 347

2 Answers2

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?

Werner
  • 603,163
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

F. Pantigny
  • 40,250