1

When I fill columns of my table with a color, it overwrites some of the lines. Is there a way to avoid it?

\documentclass[slidetop,11.5pt,xcolor=table]{beamer}
\usepackage{tikz}   
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{xcolor}
\usepackage{colortbl}

\usepackage{multirow}
\usepackage{hhline}


\begin{document}



\begin{frame}
    \frametitle{Title}
    $\rightarrow$ blablabla\\
     \begin{tabular}{c }
    \\
    \end{tabular}
        \fontsize{7.5}{7}\selectfont

    %changes the font size to 6 points and the \baselineskip to 7.2 points


    {%\centering
    \makebox[\textwidth]
    {
    \renewcommand{\arraystretch}{2.2}
    \begin{tabular}{p{1.8cm} r >{\columncolor{gray}}r r >{\columncolor{gray}}r r >{\columncolor{gray}}r r >{\columncolor{gray}}r r >{\columncolor{gray}}r }
    \hhline{*{11}{-}}
    \raggedright & \multicolumn{2}{c}{C1} & \multicolumn{2}{c}{C2} & \multicolumn{2}{c}{C3} & \multicolumn{2}{c}{C4} & \multicolumn{2}{c}{Total}\\
    \hhline{\arrayrulecolor{black}-----------}
     & nb & \% col & nb & \% col & nb & \% col & nb & \% col & nb & \% col\\\hhline{*{11}{-}}
Q5 for both  &  184 & 1,6 & 2011 & 15,8 & 2762 & 23,4 & 1121 & 14 & 6078 & \textbf{13,7}
\\ \hhline{\arrayrulecolor{black}-----------}
Q1-Q4 for F, Q5 for E & 32 & 0,3 & 414 & 3,3 & 660 & 5,6 & 1685 & 21,1 & 2791 & \textbf{6,3}\\
 \hline
Q5 for F, Q1-Q4 for E & 1746 & 14,8 & 833 & 6,5 & 214 & 1,8 &   &   & 2793 & \textbf{6,3}
\\ \hline
Q1-Q4 for both  & 9855 & 83,4 & 9465 & 74,4 & 8166 & 69,2 & 5197 & 64,9 & 32683 & \textbf{73,7}
\\ \hhline{\arrayrulecolor{black}-----------}
Total & 11817 & 100 & 12723 & 100 & 11802 & 100 & 8003 & 100 & 44345 & 100
\\ \hhline{\arrayrulecolor{black}-----------}
    \end{tabular}%
    }\par
    }

\end{frame}

\end{document}
fab
  • 11
  • \fontsize{7.5}{7}\selectfont specifies a 7.5pt font on a 7pt baseline which isn't an achievable constraint so will generate inconsistent linespacing – David Carlisle Jun 22 '15 at 10:32
  • If both xcolor and colortable are needed, don't load them separately. Instead, issue the directive \usepackage[table]{xcolor} to load them in a mutually compatible manner. – Mico Jun 22 '15 at 10:48

1 Answers1

1

I have some immediate suggestions:

  • Don't use both \makebox[\textwidth]{...} and the font-size changing command to try to make the table fit inside the text block. Providing the instructions \tiny and \setlength\tabcolsep{4.5pt} should suffice to make the table fit.

  • All of the \hhline{...} instructions can be replaced with \hline.

  • I'd change the column colors from "gray" to "lightgray".

  • If you need to load both the xcolor and the colortable packages, you should do so with the single instruction \usepackage[table]{color}. See page 9 of the user guide of the xcolor package for an explanation.

enter image description here

Even with these changes, I'd say the table is not all that readable, and various table features -- such as the fact that the numbers in the final column are typeset in bold -- are not easy to spot. Rather than use gray-striping of the columns, I'd provide more structure to the header, get rid of the distracting interior horizontal lines, and use the line-drawing macros of the booktabs package for the remaining lines. I'd also increase the font size from \tiny to \scriptsize (and, to compensate, reduce the amount of intercolumn whitespace). I think your readers will appreciate the larger lettering.

enter image description here

\documentclass[slidetop,11.5pt,xcolor=table]{beamer}
%%\usepackage{tikz}   
%%\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[table]{xcolor} % see p. 9 of UG of xcolor package
%%\usepackage{multirow}
\usepackage{hhline}

\usepackage{booktabs,array,ragged2e}  % for second table
\newcolumntype{P}[1]{>{\arraybackslash\RaggedRight}p{#1}}

\begin{document}

\begin{frame}[t]  % "[t]" just for this example
\frametitle{Title}

\tiny  % use a built-in LaTeX font size command
\setlength\tabcolsep{4.5pt}  % default: 6pt
\renewcommand{\arraystretch}{2.2}

\begin{tabular}{@{} p{1.8cm} 
           *{5}{r >{\columncolor{lightgray}}r} }
\hline
& \multicolumn{2}{c}{C1} & \multicolumn{2}{c}{C2} 
& \multicolumn{2}{c}{C3} & \multicolumn{2}{c}{C4} 
& \multicolumn{2}{c}{Total}\\
\hline
& nb & \% col & nb & \% col & nb & \% col & nb & \% col & nb & \% col\\
\hline
Q5 for both  &  184 & 1,6 & 2011 & 15,8 & 2762 & 23,4 & 1121 & 14 & 6078 & \textbf{13,7} \\ 
\hline
Q1--Q4 for F, Q5 for E & 32 & 0,3 & 414 & 3,3 & 660 & 5,6 & 1685 & 21,1 & 2791 & \textbf{6,3}\\
\hline
Q5 for F, Q1--Q4 for E & 1746 & 14,8 & 833 & 6,5 & 214 & 1,8 &   &   & 2793 & \textbf{6,3}\\ 
\hline
Q1--Q4 for both  & 9855 & 83,4 & 9465 & 74,4 & 8166 & 69,2 & 5197 & 64,9 & 32683 & \textbf{73,7} \\ 
\hline
Total & 11817 & 100 & 12723 & 100 & 11802 & 100 & 8003 & 100 & 44345 & 100 \\ 
\hline
\end{tabular}

\end{frame}

\begin{frame}[t]  % "[t]" just for this example
\frametitle{Another Title}

\scriptsize
\setlength\tabcolsep{3.5pt}  % default: 6pt
\renewcommand{\arraystretch}{1.5} % 2.2 seems excessive...

\begin{tabular}{@{} P{1.7cm} *{10}{r} @{}}
\toprule
& \multicolumn{2}{c}{C1} & \multicolumn{2}{c}{C2} 
& \multicolumn{2}{c}{C3} & \multicolumn{2}{c}{C4} 
& \multicolumn{2}{c}{Total}\\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9} \cmidrule(l){10-11} 
& nb & \%col & nb & \%col & nb & \%col & nb & \%col & nb & \%col\\
\midrule
Q5 for both  &  184 & 1,6 & 2011 & 15,8 & 2762 & 23,4 & 1121 & 14 & 6078 & \textbf{13,7} \\ 
Q1--Q4 for F, Q5 for E & 32 & 0,3 & 414 & 3,3 & 660 & 5,6 & 1685 & 21,1 & 2791 & \textbf{6,3}\\
Q5 for F, Q1--Q4 for E & 1746 & 14,8 & 833 & 6,5 & 214 & 1,8 &   &   & 2793 & \textbf{6,3}\\ 
Q1--Q4 for both  & 9855 & 83,4 & 9465 & 74,4 & 8166 & 69,2 & 5197 & 64,9 & 32683 & \textbf{73,7} \\ 
Total & 11817 & 100 & 12723 & 100 & 11802 & 100 & 8003 & 100 & 44345 & 100 \\ 
\bottomrule
\end{tabular}

\end{frame}

\end{document}
Mico
  • 506,678