2

I'm trying to have get a background color at my tables consisting of both multirows and multicolums. Without any color, the table works fine. But what I want to color expands over variable amounts of rows. I've tried to color four rows with the same color, with one cell stretching over four rows and one cell stretching over two rows.

But if I do that the second coloring, applies the color on top of the multirow text. table wouthout color

table with text

As you can see, the second line of rowcolor removes the upper part of 'Grade' from cell 1 and third row color removed the lower part of 'Grade' and lower part of Thickness. Any solution ideas?

my tex:

\begin{table}[ht]
\begin{tabular}{|c|c|lll|}
\hline
\rowcolor{blue!20} 
\multirow{4}{*}{Grades}&Yield&\multicolumn{3}{c|}{Impact bending test}\\
\rowcolor{blue!20}
                      &Strength&\multirow{2}{*}{Thickness}&Test& Impact\\
\rowcolor{blue!20}
                             &$\mathbf{R_e[N/mm^2]}$&                                &{\bf temperature}     & {\bf work}\\
\rowcolor{blue!20}
                             &\bf{transv.min.}      &\bf{ transv.}                   &$\mathbf{[\grader]}$  & {\bf [J]} \\\hline
\multirow{ 1}{*}{{\bf DH36}}   &     & {\bf 5.5 – 7.0} & {\bf         -40} & {\bf       24} \\

\hline
\end{tabular}
\end{table}
2
  • the - in \multirow{-2}{*}{ } doesnt work for me.. it just moves the text outside the table Nov 14, 2016 at 18:43
  • 1
    Please, extend your code sniped to complete document starting with \documentclass{...}, with necessary packages and your new commands definitions and ending with end{document}. In present state it is not possible to compile. Welcome to site!
    – Zarko
    Nov 14, 2016 at 19:09

2 Answers 2

1

Based on guessing about your preamble and meaning of used commands:

enter image description here

\documentclass{article}
\usepackage{siunitx}
\usepackage{makecell,multirow}
\usepackage[table]{xcolor}

\begin{document}
    \begin{table}[htb]
\sisetup{detect-weight=true}
\renewcommand\arraystretch{1.3}
\begin{tabular}{|*{2}{>{\bfseries}c|}
                 *{3}{>{\bfseries}c}|}
    \hline
\rowcolor{blue!20}
                &   &   \multicolumn{3}{c|}{\textbf{Impact bending test}}    \\
\rowcolor{blue!20}
\multirow{-2}*{Grades}  
        &   \multirow{-3}*[-1ex]{\makecell{Yield\\  Strength\\ 
                                            {$\mathbf{R_e[\si{N\per\milli\meter^2}]}$} \\transv. min.}}
                    &   \makecell{Thickness\\  transv.}    
                        &   \makecell{Test\\ temperature\\ \si{\celsius}}
                            &   \makecell{Impact\\ work\\ \si{J} }          \\
    \hline
DH36   &       & 5.5 – 7.0 & -40   & 24    \\
    \hline
\end{tabular}
    \end{table}
\end{document}

Edit: macro makecell have options b for bottom position, t for top position, l for left aligned cell content and r for right aligned. Use of it without options the cell content is vertically and horizontally centered.

If in above MWE replace the second row of table with

\multirow{-3}*{Grades}
        &   \multirow{-3}*[3pt]{\makecell{Yield\\  Strength\\
                                            {$\mathbf{R_e[\si{N\per\milli\meter^2}]}$} \\transv. min.}}
                    &   \makecell[b]{Thickness\\  transv.}
                        &   \makecell[b]{Test\\ temperature\\ \si{\celsius}}
                            &   \makecell[b]{Impact\\ work\\ \si{J} }          \\

than the table is as follows:

enter image description here

2
  • Probably, you should use [detect-weight=true].
    – Bernard
    Nov 14, 2016 at 20:30
  • @Bernard, yes, this is right key for siunitx, I consider this in edited answer
    – Zarko
    Nov 14, 2016 at 20:38
1

Here is how you can do that table with {NiceTabular} of nicematrix. You won't see thin white lines, wathever PDF viewer you use.

\documentclass{article}
\usepackage{siunitx}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\begin{table}[htb]
\sisetup{detect-weight=true}
\renewcommand\arraystretch{1.3}
\begin{NiceTabular}{|c|c|ccc|}[cell-space-top-limit=3pt]
\Hline
\RowStyle[nb-rows=2,rowcolor=blue!20]{\bfseries}
\Block{2-1}{Grades} 
   & \Block{2-1}{Yield\\ Strength\\ $\mathbf{R_e[\unit{N\per\milli\meter^2}]}$ \\transv. min.}  
     & \Block{1-3}{Impact bending test}  \\
   &   
     & \Block{}{Thickness\\  transv.}    
       & \Block{}{Test\\ temperature\\ \unit{\celsius}}
          & \Block{}{Impact\\ work\\ \unit{J}}   \\
\Hline
DH36  &  & $5.5$ -- $7.0$ & $-40$ & $24$    \\
\Hline
\end{NiceTabular}
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

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.