1

Is there a way to make macros that makes a table like this where the colors changes according to the different cells, even though the first couple of cells are a multirow cell. I need to make 16 of these tables with different amount of columns, cells etc. and it seems like a huge amount of work that could be automated a bit. I just really can't seem to find out how.

Table made using the severely impractical method shown below below

The code written to produce the table are here:

\documentclass{article}
\usepackage[utf8]{inputenc}

%===================================

\usepackage{float}
\usepackage{tabu}
\usepackage[dvipsnames,table,longtable,x11names]{xcolor}                % Definer farver med \definecolor. Se mere: 
\usepackage{multirow} % Fletning af raekker og kolonner (\multicolumn og 
\multirow) 
\usepackage{hhline} % more options for lines between rows and columns
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}} % New column type P with centering

\usepackage{geometry}
 \geometry{ a4paper, total={180mm,257mm}, left=15mm, top=60mm, bottom=0mm, textheight=180mm, footskip=10mm, headheight=52pt, }

% ====================== HARDWARE ARKITEKTUR ====================================
\begin{document}
\section{HARDWARE ARKITEKTUR} 


\begin{table}[H]
\begin{tabular}[c]{|p{2cm}|p{7cm}|P{3.5cm}|P{3.5cm}|}
\hhline{>{\arrayrulecolor{black}}|-|-|--}
    \rowcolor{NavyBlue}\textcolor{White}{\textbf{Blok-navn}} & \textcolor{White}{\textbf{Funktionsbeskrivelse}}  & \textcolor{White}{\textbf{Signaler [Porte]} }& \textcolor{White}{\textbf{Kommentar}} \\


\hhline{>{\arrayrulecolor{black}}|-|-|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!35} Force[userChoice]  & \cellcolor{NavyBlue!35} Brugerens input\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!15} SVDC [vcc]         & \cellcolor{NavyBlue!15} Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!35} Light [display]        & \cellcolor{NavyBlue!35} Viser brugerens muligheder/valg\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!15}I2C [gameStatus]    & \cellcolor{NavyBlue!15}Kommunikation mellem CPU'er\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35} \multirow[t]{-7.5}{\hsize}{Score system} & 
    \cellcolor{NavyBlue!35} \multirow[t]{-7.5}{\hsize}{Indeholder brugergrænsefladen som blandt andet er et tegn for en and i en båd med et kosteskaft og en trillebør} & \cellcolor{NavyBlue!35} WIFI [wifi] & \cellcolor{NavyBlue!35} Forbindelse til Database\\


\hhline{>{\arrayrulecolor{black}}|-|-|--}


    \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!15}  &  \cellcolor{NavyBlue!15}5VDC [vcc] & \cellcolor{NavyBlue!15}Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--} 
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!35} 12VDC [powerRail] & \cellcolor{NavyBlue!35} Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!15} IR [dryerSensor] & \cellcolor{NavyBlue!15} IR modtager\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!35} IR [cupSensor] & \cellcolor{NavyBlue!35} IR modtager\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!15} IR [dryerLED] & \cellcolor{NavyBlue!15} IR modtager\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!35} IR [cupLED] & \cellcolor{NavyBlue!35}IR modtager\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!15} Light [target] & \cellcolor{NavyBlue!15}Visuelt lys fra kopperne\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!35} Airflow [airflow] & \cellcolor{NavyBlue!35}Luft til at tørre bolden\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15} \multirow[t]{-10.5}{\hsize}{Cup Zone} & 
    \cellcolor{NavyBlue!15} \multirow[t]{-10.5}{\hsize}{ Sørger for detektering af kopper og bolde i kopperne, og aktivering af motoren i Ball Dryer. Desuden styres belysning under kopperne også her.} & \cellcolor{NavyBlue!15} I2C [gameStatus] & \cellcolor{NavyBlue!15}Kommunikation mellem blokkene\\


\hhline{>{\arrayrulecolor{black}}|-|-|--}


    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!35}5VDC [vcc] & \cellcolor{NavyBlue!35}Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!15}12VDC [powerRail] & \cellcolor{NavyBlue!15}Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--} 
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!35} Sound [audio] & \cellcolor{NavyBlue!35} Musik der analyseres\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!15} Light [matrixLight] & \cellcolor{NavyBlue!15} Bordplade lysmønster\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35}  & \cellcolor{NavyBlue!35} & \cellcolor{NavyBlue!35} Light [bgLight] &\cellcolor{NavyBlue!35} Bordplade baggrundsbelysning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!35}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!35} \multirow[t]{-7.5}{\hsize}{Light Panel} & 
    \cellcolor{NavyBlue!35} \multirow[t]{-7.5}{\hsize}{Her styres den grafiske belysning på bordet. Belysningen består af en matrix og baggrundsbelysning.} & \cellcolor{NavyBlue!15} I2C [gameStatus] & \cellcolor{NavyBlue!15} Kommunikation bellem blokkene\\


\hhline{>{\arrayrulecolor{black}}|-|-|--}


    \cellcolor{NavyBlue!15}  & \cellcolor{NavyBlue!15} & \cellcolor{NavyBlue!35} 5VDC [vcc] & \cellcolor{NavyBlue!35} Spændingsforsyning\\
\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|>{\arrayrulecolor{NavyBlue!15}}->{\arrayrulecolor{black}}|--}
    \cellcolor{NavyBlue!15} \multirow[t]{-2}{\hsize}{Power Supply} & 
    \cellcolor{NavyBlue!15} \multirow[t]{-2}{\hsize}{Forsyner systemet med strøm} & \cellcolor{NavyBlue!15} 12VDC [powerRail] & \cellcolor{NavyBlue!15} Spændingsforsyning\\


\hhline{>{\arrayrulecolor{black}}|-|-|--}
\end{tabular} 

\caption{Blokbeskrivelse APP}
\label{Blokbeskrivelse APP}
\end{table}

\end{document}

Finally there is a working example at this URL: ShareLatex working example

  • There should be a way to “program” the colors so that you don't need to explicitly say which one for each cell, but I don't know the packages. At the very least you could aim to have \singlerow{Score system}{Indeholder …}{Force [userChoice], SVDC [vcc], …}{Brugerens input, Spændingsforsyning, …}. It would be nice if someone that knows how to do this in ConTeXt posted an answer as an informative solution, by the way. – Manuel Oct 28 '17 at 18:09
  • 1
    If you use \usepackage[table]{xcolor} you can call the command \rowcolors{<starting row>}{<color1>}{<color2>} which colours the rows of a table in alternating colours. Then you can use the command \cellcolor in the \multirow cells to set their colour explicitly. And for the first row you use \rowcolor{<color>} – Skillmon Oct 28 '17 at 18:15
  • You say that you need to make "16 of these tables with different amount of columns, cells etc. " Can you give some indication of what the input parameters are? It is hard to automate a process without knowing what the parameters are. – Andrew Oct 28 '17 at 19:52
  • The different tables are of the following setup: 4 columns, first row title 1 row, 1 row, 5 rows, 5 rows, 1 row, 1 row, 9 rows, 9 rows, 1 row, 1 row, 6 rows, 6 rows, 1 row, 1 row, 2 rows, 2 rows. The columns of the left side, the 1's, need to switch color according to each other, and the columns on the right side need to switch according to each other, without affecting the other ones. Just like shown on the example. Another table could be: 6 columns, title row, 1,1,1,1,1,1, 1,1,1,1,3,1, 1,1,1,1,2,1, 1,1,1,4,4,1, and so on. So there is different amounts of rows per column. – sskieller Oct 29 '17 at 9:52
  • On this table there the colors needs to follow like above, where one half is colored according to that half's columns and the other half is colored according to the other half's columns. So it is either 4 or 6 columns – sskieller Oct 29 '17 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.