[Tex/LaTex] \rowcolor not working in latex IEEEtrans

colorcolortblieeetranmultirowtables

I am trying to colour rows in some tables in a latex IEEEtran article but the colouring does not show at all, and no error is thrown as well.
Here is the snippet of code I used:

\usepackage{array, booktabs, makecell, tabularx}
\usepackage[pdftex]{graphicx}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{subfigure}
\usepackage{float}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage{amsmath}
\setcellgapes{4pt}%parameter for the spacing
\usepackage{mdwmath}
\usepackage{mdwtab}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{multirow}
\begin{document}
            \begin{table*}[t]
             \centering
             \caption{Some of the previous DBQ studies in the literature} \label{tab:Studies}
             \begin{tabular}{lccl}
               &&&\\
               \rowcolor{gray!20}
               \multirow{-2}{*}{\textbf{Country}} & \multirow{-2}{*}{\textbf{DBQ type}} & \multirow{-2}{*}{\textbf{Year published}} & \multirow{-2}{*}{\textbf{Resulting factors}}\\
                \rowcolor{gray!20}
                \midrule
                \multirow{2}{*}{UK\cite{parker1995}}& \multirow{3}{*}{....} & \multirow{3}{*}{1995} & driving under influence \\
                &&& driving while texting\\
                \bottomrule
             \end{tabular}
            \end{table*}
\end{document}

Best Answer

  • package mdwtab is not compatible with the package colortbl, consequently with it row colors not show up
  • ieee journals doesn't allows colored tables
  • your table code is unnecessary complicated. do you really need all this multirows and table over two columns? with example of table, which you provide it can be easily fit in one column.
  • if you persist with colored row with column headers than a possible mwe (mnimal working example) can be:

    \documentclass[twocolumn]{IEEEtran}
    \usepackage{booktabs, cellspace, multirow, tabularx}
        \setlength\cellspacetoplimit{4pt}
        \setlength\cellspacebottomlimit{4pt}
        \newcolumntype{R}{>{\raggedright\arraybackslash}X}
        \addparagraphcolumntypes{R}
    \usepackage{ragged2e}
    
    \usepackage[table]{xcolor}
    \usepackage[export]{adjustbox}
    \usepackage{amsmath}
    
    \usepackage[colorlinks,allcolors=blue]{hyperref}
    \usepackage{lipsum}
    
    \begin{document}
    \lipsum[66]
        \begin{table}[htb]
    \centering
    \caption{Some of the previous DBQ studies in the literature} \label{tab:Studies}
    \begin{tabularx}{\linewidth}{l c c S{R}}
    \rowcolor{gray!20}
    \textbf{Country}
        & \textbf{DBQ type} & \textbf{Year published} & \textbf{Resulting factors}  \\
    %
    UK\cite{parker1995}
        &                   & 1995                      & driving under influence   \\
    ...
        & ...               & ...                       & driving while texting     \\
        \bottomrule
    \end{tabularx}
        \end{table}
    \lipsum[1-5]
    \end{document}
    

enter image description here

  • above table is simple to extend to table*
  • if cell contents in your table is bigger, please provide three rows of table which emulate your real table.
Related Question