3

I want to color a column, but only starting from the row that starts with C1. I have this example output. I want to remove the yellow color from the row before C1.

This is how it looks: enter image description here

This is the script:

\documentclass[10pt]{llncs}
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell, booktabs, caption}
\usepackage{multicol} 
\usepackage{multirow} 
\usepackage{adjustbox} 
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{sistyle} % for numbers 
\SIthousandsep{,} % for numbers
\usepackage{xcolor}
\usepackage{colortbl}
\definecolor{lightYellow}{cmyk}{0,0.04,4.4,0}   

\begin{document}

\title{Title}
\maketitle

\begin{abstract}
Abstract
\end{abstract}

\section{Section1}
\begin{table*}[!tp]
    \centering
    \caption{some table}
    \label{tab:example} 
    \begin{adjustbox}{max width=\textwidth}     
        \begin{tabular}{l>{\columncolor{lightYellow}}r@{\hspace{5pt}}>{\columncolor{lightYellow}}rr@{\hspace{5pt}}r}

            \toprule 
            \multirow{2}{*}{Criterion} &
            \multicolumn{2}{c}{\multirow{2}{*}{Result}}&  
            \multicolumn{2}{c}{Country} \\
            \cline{4-5}
            & & &\multicolumn{2}{c}{AU}  \\
            \midrule 

            C1  & \num{11}&(0.11\%) & \num{22} &(0.22\%) \\

            C2  & \num{33} & (0.33\%) & \num{44}&(0.44\%)\\

            \midrule 
            C3  & \num{44}&(0.44\%) & \num{55}&(0.55\%)\\

            C4  & \num{66}&(0.66\%)&\num{77}&(0.77\%)\\
            \bottomrule
        \end{tabular}
    \end{adjustbox}
\end{table*}


\bibliographystyle{splncs04}
\bibliography{ref}
\end{document}
qbq
  • 53
  • \toprule \multirow{2}{*}{Criterion} & \cellcolor{white}& \cellcolor{white} & \multicolumn{2}{c}{Country} \\ \cline{4-5} & \multicolumn{2}{c}{\multirow{-2}{*}{Result}} &\multicolumn{2}{c}{AU} \\ will give you the desired result. – leandriis Jul 03 '19 at 12:18

3 Answers3

1

Here is a solution, with two \rowcolor{white} and \multirow{-2} in the following row. Note that sistyle has been superseded by siunitxand that xcolor with option [table] already loads colortbl. Also, you shouldn't use adjustbox with tables, as it leads to inconsistent font sizes`.

\documentclass[10pt]{llncs}
\usepackage{array}
\usepackage{makecell, booktabs}
\usepackage{multirow}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{siunitx}
\sisetup{group-separator={,}}
\usepackage[table]{xcolor}
\definecolor{lightYellow}{cmyk}{0,0.04,4.4,0}

\begin{document}

\section{Section1}
\begin{table*}[!tp]
    \centering
    \caption{some table}
    \label{tab:example}
        \begin{tabular}{l@{\hspace{5pt}}*{2}{>{\columncolor{lightYellow}}r}@{\hspace{10pt}}rr}
            \toprule
   \rowcolor{white} & & &
            \multicolumn{2}{c}{Country} \\
            \cmidrule{4-5}
   \rowcolor{white}
            \multirowcell{-2}{Criterion} & \multicolumn{2}{c}{\multirowcell{-2}{Result}} &\multicolumn{2}{c}{AU} \\
            \midrule
            C1 & \num{11}&(0.11\%) & \num{22} &(0.22\%) \\
            C2 & \num{33} & (0.33\%) & \num{44}&(0.44\%)\\
            \midrule
            C3 & \num{44}&(0.44[![enter image description here][1]][1]\%) & \num{55}&(0.55\%)\\
            C4 & \num{66}&(0.66\%)&\num{77}&(0.77\%)\\
            \bottomrule
        \end{tabular}
\end{table*}%

\end{document} 
Bernard
  • 271,350
  • I use adjustbox because my real table has many columns. Without the adjustbox the table width goes beyond the page width limit. How can I manage to shrink a table in my page if it has many tables? – qbq Jul 03 '19 at 14:16
  • @qbq: There are plenty of options on how to make a too wide table fit into the textwidth. Reducing the font size, decreasing the horizontal white space between columns and allowing linebreaks in table cells are just a few of them. You might want to have a look at: My table doesn't fit; what are my options? – leandriis Jul 03 '19 at 16:12
0

The table is considered as a tikzpicture.

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{table}[t]
\centering
%\caption{Some table}
\label{tab:example}
\begin{tikzpicture}[xscale=3.5,yscale=1.2]
\draw
(0,1) node{Results} 
+(180:1) node[right]{Criterion}
++(0:1)--+(0:.25)--+(180:.25)
+(90:.2) node{Country} +(-90:.2) node{AU};

\fill[yellow,shift={(-.5,.5)}] (0,0) rectangle +(1,-2);

\path[every node/.style={align=center}]
(0,0)   node{$11\quad (0.11\%)$\\$33\quad (0.33\%)$}
(1,0)   node{$22\quad (0.22\%)$\\$44\quad (0.44\%)$}
(0,-1)  node{$44\quad (0.44\%)$\\$66\quad (0.66\%)$}
(1,-1)  node{$55\quad (0.55\%)$\\$77\quad (0.77\%)$}
(-1,0)  node[right]{C1\\C2}
(-1,-1) node[right]{C3\\C4};

\foreach \i in {-2,...,1}
\draw[shift={(90:.5)}] (-1,\i)--+(0:2.35);
\end{tikzpicture}
\end{table}%
\end{document} 
Black Mild
  • 17,569
0

With {NiceTabular} of nicematrix (with its key color-inside), you only have to add an instruction \rowlistcolors{lightYellow}[cols={2,3}] in the beginning of the third row.

\documentclass[10pt]{llncs}
\usepackage{booktabs}
\usepackage{multirow} 
\usepackage{sistyle}
\SIthousandsep{,}
\usepackage{xcolor}
\usepackage{nicematrix}
\definecolor{lightYellow}{cmyk}{0,0.04,4.4,0}

\begin{document}

\begin{table}[!tp] \centering \caption{some table} \begin{NiceTabular}{lr@{\hspace{5pt}}rr@{\hspace{5pt}}r}[color-inside] \toprule \multirow{2}{}{Criterion} & \multicolumn{2}{c}{\multirow{2}{}{Result}}&
\multicolumn{2}{c}{Country} \ \cline{4-5} & & &\multicolumn{2}{c}{AU} \ \midrule \rowlistcolors{lightYellow}[cols={2,3}] C1 & \num{11}&(0.11%) & \num{22} &(0.22%) \ C2 & \num{33} & (0.33%) & \num{44}&(0.44%)\ \midrule C3 & \num{44}&(0.44%) & \num{55}&(0.55%)\ C4 & \num{66}&(0.66%)&\num{77}&(0.77%)\ \bottomrule \end{NiceTabular} \end{table}

\end{document}

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

Output of the above code

It's also possible to put an instruction in the beginning of the array (in the so-called \CodeBefore provided by {NiceTabular}).

\documentclass[10pt]{llncs}
\usepackage{booktabs}
\usepackage{multirow} 
\usepackage{sistyle}
\SIthousandsep{,}
\usepackage{xcolor}
\usepackage{nicematrix}
\definecolor{lightYellow}{cmyk}{0,0.04,4.4,0}

\begin{document}

\begin{table}[!tp] \centering \caption{some table} \begin{NiceTabular}{lr@{\hspace{5pt}}rr@{\hspace{5pt}}r} \CodeBefore \rectanglecolor{lightYellow}{3-2}{6-3} \Body \toprule \multirow{2}{}{Criterion} & \multicolumn{2}{c}{\multirow{2}{}{Result}}&
\multicolumn{2}{c}{Country} \ \cline{4-5} & & &\multicolumn{2}{c}{AU} \ \midrule C1 & \num{11}&(0.11%) & \num{22} &(0.22%) \ C2 & \num{33} & (0.33%) & \num{44}&(0.44%)\ \midrule C3 & \num{44}&(0.44%) & \num{55}&(0.55%)\ C4 & \num{66}&(0.66%)&\num{77}&(0.77%)\ \bottomrule \end{NiceTabular} \end{table}

\end{document}

The output if the same.

F. Pantigny
  • 40,250