Graphics, Figures & TablesProblems with table coloring

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
prohormitrich53

Problems with table coloring

Post by prohormitrich53 »

Hello! I need to repeat this table in LaTeX:
Image
If I try to keep task-like spacing, it brakes when I plug xcolor or colortbl packages.

Code of the first try:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{pbox}
\usepackage{tabls}
%\usepackage[table]{xcolor}   try to delete comment sign

\begin{document}

\begin{table}[h!]
	\begin{center}
	{\tablinesep=2ex\tabcolsep=10pt
		\begin{tabular}{@{}|l|l|l|l|l|l|l|@{}}
			\hline
			\multicolumn{7}{|c|}{} \\[-0.4cm]
			\hline		
			\multicolumn{2}{|l|}{\pbox{3cm}{Observed $\text{CL}_\text{s}$ \\ compared with \\$\text{J}^\text{p}=0^+$}} & \pbox{1.5cm}{$0^- \, (gg)$ \\ pseudo-scalar} & \pbox{1.6cm}{$2_\text{m}^+ \, (gg)$ \\ minimal couplings} & \pbox{1.6cm}{$2_\text{m}^+ \, (q\bar{q})$ \\ minimal couplings} & \pbox{1.5cm}{$1^- (q\bar{q})$ exotic vector} & \pbox{2.5cm}{$1^+ (q\bar{q})$ \\ exotic pseudo-vector} \\
			\hline 
			\multirow{2}*{$\text{ZZ}^{(*)}$} & ATLAS & 2.2\% & 6.8\% & 16.8\% & 6.0\% & 0.2\% \\
			\cline{2-7}
									& CMS & 0.16\% & 1.5\% & <0.1\% & <0.1\% & <0.1\% \\
			\hline
			\multirow{2}*{$\text{WW}^{(*)}$} & ATLAS & --- & 5.1\% & 1.1\% & --- & --- \\
			\cline{2-7}
									& CMS & --- & 14\% & --- & --- & --- \\
			\hline
			$\gamma\gamma$ & ATLAS & --- & 0.7\% & 12.4\% & --- & --- \\
			\hline 
		\end{tabular}
		}
	\end{center}
\end{table}

\end{document}
Before add packages:
Image
After add packages:
Image
If I do not keep spacing, some vertical and horizontal lines vanishes when I try to add color. Code of the second try:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{color,colortbl}
\definecolor{header}{RGB}{0,84,165}
\definecolor{body}{RGB}{228,232,244}
\begin{document}
\newcolumntype{g}{>{\columncolor{header}}c}
\newcolumntype{d}{>{\columncolor{body}}c}
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{|p{1.2cm}|p{1.1cm}|p{1.4cm}|p{1.9cm}|p{1.7cm}|p{1.9cm}|p{2.7cm}|}			
			\hline
			\rowcolor{header}			
			\multicolumn{7}{|c|}{} \\
			\hline
			\rowcolor{body}		
			\multicolumn{2}{|p{2.89cm}|}{Observed $\text{CL}_\text{s}$ compared with $\text{J}^\text{p}=0^+$} & $0^- \, (gg)$ pseudo-scalar & $2_\text{m}^+ \, (gg)$ minimal couplings & $2_\text{m}^+ \, (q\bar{q})$ minimal couplings & $1^- (q\bar{q})$ exotic vector & $1^+ (q\bar{q})$ exotic pseudo-vector \\
			\hline
			\rowcolor{body}
			\multirow{-2}*{} & ATLAS & 2.2\% & 6.8\% & 16.8\% & 6.0\% & 0.2\% \\
			\cline{2-7}
			\rowcolor{body}
					\raisebox{0.2cm}[-1cm]{$\text{ZZ}^{(*)}$}				& CMS & 0.16\% & 1.5\% & <0.1\% & <0.1\% & <0.1\% \\
			\hline
			\rowcolor{body}
			\multirow{-2}*{} & ATLAS & --- & 5.1\% & 1.1\% & --- & --- \\
			\cline{2-7}
			\rowcolor{body}
						\raisebox{0.2cm}[-1cm]{$\text{WW}^{(*)}$}		& CMS & --- & 14\% & --- & --- & --- \\
			\hline
			\rowcolor{body}
			$\gamma\gamma$ & ATLAS & --- & 0.7\% & 12.4\% & --- & --- \\			
			\hline 	
		\end{tabular}
	\end{center}
\end{table}

\end{document}
Result:
Image
No one solution from this site could not help me, so, I really do not know what to do. Please, help to fix this problem
Last edited by Stefan Kottwitz on Sun Feb 28, 2016 3:05 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problems with table coloring

Post by Johannes_B »

Two suggestions:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{geometry}% narrower margins for this test
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{showframe}
\usepackage{siunitx}
\definecolor{header}{RGB}{0,84,165}
\definecolor{body}{RGB}{228,232,244}
\newcolumntype{L}[1]{>{\raggedright}m{#1\textwidth}}
\begin{document}
\newcolumntype{g}{>{\columncolor{header}}c}
\newcolumntype{d}{>{\columncolor{body}}c}
\begin{table}%[h!]
	\centering
	\begin{tabular}{|p{1.2cm}|%
%			p{0.6cm}% value chnged
		p{1.6cm}% value chnged
		|p{1.4cm}|p{1.9cm}|p{1.7cm}|p{1.9cm}|p{2.7cm}|}                      
		\hline
		\rowcolor{header}                      
		\multicolumn{7}{|c|}{} \\
		\hline
		\rowcolor{body}        
		\multicolumn{2}{|p{2.89cm}|}{Observed $\text{CL}_\text{s}$ compared with $\text{J}^\text{p}=0^+$} &
		$0^- \, (gg)$ pseudo-scalar & $2_\text{m}^+ \, (gg)$ minimal couplings & $2_\text{m}^+ \, (q\bar{q})$ minimal couplings & $1^- (q\bar{q})$ exotic vector & $1^+ (q\bar{q})$ exotic pseudo-vector \\
		\hline
		\rowcolor{body}
		\multirow{-2}*{} & ATLAS & 2.2\% & 6.8\% & 16.8\% & 6.0\% & 0.2\% \\
		\cline{2-7}
		\rowcolor{body}
		\raisebox{0.2cm}[-1cm]{$\text{ZZ}^{(*)}$}                               & CMS & 0.16\% & 1.5\% & <0.1\% & <0.1\% & <0.1\% \\
		\hline
		\rowcolor{body}
		\multirow{-2}*{} & ATLAS & --- & 5.1\% & 1.1\% & --- & --- \\
		\cline{2-7}
		\rowcolor{body}
		\raisebox{0.2cm}[-1cm]{$\text{WW}^{(*)}$}               & CMS & --- & 14\% & --- & --- & --- \\
		\hline
		\rowcolor{body}
		$\gamma\gamma$ & ATLAS & --- & 0.7\% & 12.4\% & --- & --- \\                   
		\hline  
	\end{tabular}
\end{table}

\newcommand{\noVal}{{---}}
\noindent
\begin{tabular}{ccS[table-format=1.2]
		S[table-format=2.1]
		S[table-format=2.1,table-comparator=true]
		S[table-format=1.1,table-comparator=true]
		S[table-format=1.1,table-comparator=true]
	}
	\rowcolor{header}
	\multicolumn{7}{|c|}{} \\
	\rowcolor{body}        
	\multicolumn{2}{L{.21}}{Observed CL\textsubscript{s} compared with $J\text{p}=0^+$} &
	\multicolumn{1}{L{.12}}{$0^- \, (gg)$ pseudo-scalar in~\%}&
	\multicolumn{1}{L{.12}}{$2_\text{m}^+ \, (gg)$ minimal couplings in~\%}&
	\multicolumn{1}{L{.12}}{$2_\text{m}^+ \, (q\bar{q})$ minimal couplings in~\%}&
	\multicolumn{1}{L{.12}}{$1^- (q\bar{q})$ exotic vector in~\%}&
	\multicolumn{1}{L{.12}}{$\rule{0pt}{3ex} 1^+ (q\bar{q})$ exotic pseudo-vec\-tor in~\%\rule[-2ex]{0pt}{3ex}} \\
	\rowcolor{body}
	 $\text{ZZ}^{(*)}$& ATLAS & 2.2 & 6.8 & 16.8 & 6.0 & 0.2 \\
	\rowcolor{body}
	& CMS & 0.16 & 1.5 & < 0.1 & < 0.1 & < 0.1 \\[2ex]
	\rowcolor{body}
	$\text{WW}^{(*)}$& ATLAS & \noVal & 5.1 & 1.1 & \noVal & \noVal \\
	\rowcolor{body}
	& CMS & \noVal & 14 & \noVal & \noVal & \noVal \\[2ex]
	\rowcolor{body}
	$\gamma\gamma$ & ATLAS & \noVal & 0.7 & 12.4 & \noVal & \noVal \\[1ex]
\end{tabular}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply