3

I am using TexStudio with Bibtex. I want to color a multirow table. While, I have seen some questions put up earlier in this forum about that, however still I am not able to resolve the problem.

The code for a small sample table is given as follows:

 \begin{table}[]
\begin{tabular}{|c|c|c|c|}
    \hline
 \multirow{2}{*}{Methods} & \multicolumn{3}{c|}{Example 1} \\ \cline{2-4} 
& ISE      & IAE      & ITAE     \\ \hline
    Abc                      & 0.1      & 0.2      & 0.3      \\ \hline
    Xyz                      & 0.4      & 0.5      & 0.6      \\ \hline
\end{tabular}
\end{table}

Please guide me how to color the cell containing the word "Methods"

ShJ
  • 891

2 Answers2

4

How about this? (cf. this answer.)

\documentclass{article}
\usepackage{colortbl,multirow,xcolor}
\begin{document}
\begin{table}[]
\begin{tabular}{|c|c|c|c|}
    \hline
\cellcolor{red!50}  & \multicolumn{3}{c|}{ Example 1} \\ \cline{2-4} 
\multirow{-2}{*}{\cellcolor{red!50} Methods} & ISE      & IAE      & ITAE     \\ \hline
    Abc                      & 0.1      & 0.2      & 0.3      \\ \hline
    Xyz                      & 0.4      & 0.5      & 0.6      \\ \hline
\end{tabular}
\end{table}
\end{document}

enter image description here

  • I want to color the cell having the word "Methods". When I use \cellcolor{red!50} to color methods, it colors only half of it. I want to color the complete cell "Methods" – ShJ Feb 21 '19 at 05:16
  • @ShiS Sorry about this. Changed. –  Feb 21 '19 at 05:20
0

Here is a way to construct that table with {NiceTabular} of nicematrix. You need several compilations.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{table} \begin{NiceTabular}{cccc}[hvlines,color-inside] \Block[fill=red!50]{2-1}{Methodes} & \Block{1-3}{ Example 1} \ & ISE & IAE & ITAE \ Abc & 0.1 & 0.2 & 0.3 \ Xyz & 0.4 & 0.5 & 0.6
\end{NiceTabular} \end{table}

\end{document}

Output of the above code

You will have a perfect output, in all the PDF viewers.

F. Pantigny
  • 40,250