1

I want to center the multirow cells vertically, but because I need to color them aswell, I can't use \multirowcell from the makecell package as it is not compatible. Therefore, I used the shortstack command to achieve a linebreak, but the vertical alignment seems to be random.

Please don't suggest altering the table without color or the booktabs package.

enter image description here

MWE:

\documentclass[10pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{makecell}

\usepackage[usenames, table ,xcdraw]{xcolor}
    \definecolor{mgrau1}{RGB}{230, 230, 230}
    \definecolor{mgrau2}{RGB}{204, 204, 204}

\newcommand{\multirc}[2]{\multirow{#1}{*}{\shortstack[c]{#2}}}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newcolumntype{M}[1]{>{\centering}m{#1}}
\usepackage{hhline}

\begin{document}

\begin{table}
    \setlength\tabcolsep{3.3pt}
    \renewcommand{\arraystretch}{1.2}
    \centering\footnotesize
    \begin{tabular}{|>{\columncolor{mgrau2}}M{1.5cm}|>{\columncolor{mgrau1}}M{1.5cm}|P{2.2cm}|}
        \hline
        \multicolumn{2}{|c|}{} & \\
        \hhline{|~~|~|}
        \multicolumn{2}{|c|}{\multirowcell{-2}{Prozesselement/\\Funktion}} & \multirowcell{-2}{mögliche Fehler}  \\
        \Xhline{2\arrayrulewidth}
        &  &  \\
        \hhline{|>{\arrayrulecolor{mgrau2}}->{\arrayrulecolor{mgrau1}}->{\arrayrulecolor{black}}|-|}
        & \multirc{-2}{STL-Datei\\reparieren} & this is a really long text spanning multiple lines \\
        \hhline{|>{\arrayrulecolor{mgrau2}}->{\arrayrulecolor{black}}|-|-|}
        &  & this is a really long text spanning multiple lines \\
        \hhline{|>{\arrayrulecolor{mgrau2}}->{\arrayrulecolor{mgrau1}}->{\arrayrulecolor{black}}|-|}
        & \multirc{-2}{STL-Datei\\verkleinern} &  \\
        \hhline{|>{\arrayrulecolor{mgrau2}}->{\arrayrulecolor{black}}|-|-|} 
        &  & this is a really long text spanning multiple lines \\
        \hhline{|>{\arrayrulecolor{mgrau2}}->{\arrayrulecolor{mgrau1}}->{\arrayrulecolor{black}}|-|}
        \multirc{-6}{Baujobvor-\\bereitung} & \multirc{-2}{STL-Datei\\platzieren} & this is a really long text spanning multiple lines \\
        \hline
    \end{tabular}
\end{table}

\end{document}
1

I thought I would do that easily with the latest version of nicematrix but I found a small bug in that version.

You can found a corrected version of nicematrix.sty here : nicematrix.sty

(I will upload this corrected version on CTAN soon).

With this version, it's easy to do the tabular (you need several compilations).

\documentclass[10pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{nicematrix}
\usepackage{makecell}    
\definecolor{mgrau1}{RGB}{230, 230, 230}
\definecolor{mgrau2}{RGB}{204, 204, 204}        
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\arraybackslash
  \RaggedRight\hspace{0pt}}m{#1}}
\newcolumntype{M}[1]{>{\centering}m{#1}}        

\begin{document}

\begin{table}
\setlength\tabcolsep{3.3pt}
\renewcommand{\arraystretch}{1.2}
\centering\footnotesize
\begin{NiceTabular}{|M{1.5cm}|M{1.5cm}|P{2.2cm}|}%
[code-before = \rectanglecolor{mgrau2}{2-1}{7-1} \rectanglecolor{mgrau1}{2-2}{7-2}]
\hline
\multicolumn{2}{|C|}{\makecell{Prozesselement \\ Funktion}} 
& mögliche Fehler \\
\hline
\Block{6-1}{\makecell{Baujobvor \\ beritugn}}
& 
\Block{2-1}{\makecell{STL-Datei\\ reparieren}}
& \\
\cline{3-3}
 & & 
this is a really long text spanning multiple lines \\
\cline{2-3}
 & \Block{2-1}{\makecell{STL-Datei\\ reparieren}} & 
this is a really long text spanning multiple lines
\\
\cline{3-3}
 & & 
\\
\cline{2-3}
 & \Block{2-1}{\makecell{STL-Datei\\ reparieren}} &  
this is a really long text spanning multiple lines \\
\cline{3-3}
 & & 
this is a really long text spanning multiple lines\\
\hline
\end{NiceTabular}
\end{table}

\end{document}

Result of the above code

| improve this answer | |
  • are those commands only available in a NiceTable environment or can they be used in conjunction with other tables such as tabularx or longtable? – fuj36840 May 13 at 18:05
  • 1
    As for now, they are only available in the environment {NiceTabular}. Maybe in a future version... – F. Pantigny May 13 at 18:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.