彩色多行的垂直对齐

彩色多行的垂直对齐

我想让multirow单元格垂直居中,但因为我还需要为它们着色,所以我无法使用\multirowcellmakecell包,因为它不兼容。因此,我使用命令shortstack来实现换行,但垂直对齐似乎是随机的。

请不要建议更改没有颜色的表格或booktabs包装。

在此处输入图片描述

梅威瑟:

\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

与。{NiceTabular}nicematrix

\documentclass[10pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{nicematrix}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}\arraybackslash}m{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}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}|}[hvlines] 
\CodeBefore
  \rectanglecolor[RGB]{204, 204, 204}{2-1}{7-1} 
  \rectanglecolor[RGB]{230, 230, 230}{2-2}{7-2}
\Body
    \Block{1-2}{Prozesselement \\ Funktion} & & mögliche Fehler \\
    \Block{6-1}{Baujobvor \\ beritugn} & \Block{2-1}{STL-Datei\\ reparieren} \\
     & & this is a really long text spanning multiple lines \\
     & \Block{2-1}{STL-Datei\\ reparieren} & this is a really long text spanning multiple lines \\
    & & \\
     & \Block{2-1}{STL-Datei\\ reparieren} &  this is a really long text spanning multiple lines \\
     & &  this is a really long text spanning multiple lines\\
\end{NiceTabular}
\end{table}

\end{document}

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的结果

相关内容