1

3rd row is halfway cut

How can I fix the 3rd row? The word is halfway cut.

\begin{center}
    \centering
  \rowcolors{2}{gray!25}{white}
  \captionof{table}{aa} \label{tab:t1}
  \vspace{0.3cm}
  \renewcommand\arraystretch{1.3}
  \begin{tabular}{c c c c c}
    \rowcolor{gray!50}
    External Stimulus & Dimension & Material & Fabrication Technique & Ref.\\
    \hline
    Temperature & Some values & Some values & qq & 1\\   \hline 
    \multirow{2}*{Light} & Some values & Some values & rr &2\\\cline{2-5}
    & Some values & Some values & zz &3\\\hline
    Magnetic field & Some values & Some values & d & 4\\\hline
    pH & 3D & e & mm & 5\\
  \end{tabular}
\end{center}
Miro
  • 11

2 Answers2

1

Put "Light" on the last row of the multirow, and use \multirow{-2}*{Light} instead.

In other words, change to

  \begin{tabular}{c c c c c}
    \rowcolor{gray!50}
    External Stimulus & Dimension & Material & Fabrication Technique & Ref.\\
    \hline
    Temperature & Some values & Some values & qq & 1\\   \hline 
    & Some values & Some values & rr &2\\\cline{2-5}
    \multirow{-2}*{Light} & Some values & Some values & zz &3\\\hline
    Magnetic field & Some values & Some values & d & 4\\\hline
    pH & 3D & e & mm & 5\\
  \end{tabular}

The reason is that currently the code draws the first row of the Light rows, with the text drawn offset to be low, and then it draws the second row. But when you draw the second row with the background color, it paints over the lowered text from the first row. So to fix it, draw all background first and then put the text. More detailed explanation is given on pages 8-9 of the multirow package manual.

I am not sure whether this works well with the \rowcolors specification. You may need to color each row individually.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • Hm... I should've searched TeX.SE before I wrote the answer. Better explanations and alternative solutions are available at https://tex.stackexchange.com/q/269547/119 some of which works also with automatic row coloring. – Willie Wong Apr 19 '21 at 15:52
  • 1
    I can confirm it does work with \rowcolors. – Bernard Apr 19 '21 at 15:53
0

You can do that table with {NiceTabular} of nicematrix with a perfect result in all the PDF viewers (no thin white lines).

\documentclass{article}
\usepackage{nicematrix}
\usepackage{caption}

\begin{document}

\begin{center} \centering \captionof{table}{aa} \label{tab:t1} \vspace{0.3cm} \renewcommand\arraystretch{1.3} \begin{NiceTabular}{c c c c c} \CodeBefore \rowcolors{2}{gray!25}{}[respect-blocks] \rowcolor{gray!50}{1} \Body External Stimulus & Dimension & Material & Fabrication Technique & Ref.\ \hline Temperature & Some values & Some values & qq & 1\ \hline \Block{2-1}{Light} & Some values & Some values & rr &2\\cline{2-5} & Some values & Some values & zz &3\\hline Magnetic field & Some values & Some values & d & 4\\hline pH & 3D & e & mm & 5\ \end{NiceTabular} \end{center}

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250