1

Still dealing with fancy tables, now I am trying to get one with multicolumn and multirow cells.

I can get multicolumn cells right, but I am still struggling with multirow ones.

MWE in Beamer:

\documentclass[xcolor={dvipsnames,table}]{beamer}

%%TABLE
\usepackage{multirow}
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}

\mode<presentation> {
    \usetheme[compress]{Singapore}
    \usecolortheme{orchid}
}

\begin{document}

\begin{frame}
    \sffamily
    \arrayrulecolor{white}
    \arrayrulewidth=1pt
    \renewcommand{\arraystretch}{1}
    \rowcolors[\hline]{2}{.!50!White}{}
    \resizebox{\linewidth}{!}{%
        \begin{tabular}{A|A|A|A|A|B|B|B|A}
            \rowcolor{.!50!Black}
            \multicolumn{5}{A|}{\arraycolor{White}\bfseries 14 subjects} &
            \multicolumn{3}{B|}{\arraycolor{White}\bfseries 10 subjects} &
            \multirow{2}{*}{\arraycolor{White}\bfseries Control}\\
            \rowcolor{.!50!Black}
            \multicolumn{3}{A|}{\arraycolor{White} Surface} &
            \multicolumn{2}{A|}{\arraycolor{White} Follicle} &
            \multicolumn{3}{B|}{\arraycolor{White} Surface} & \\
            No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
        \end{tabular}
    }%
\end{frame} 

\end{document}

I need to make the "Control" cell span 2 rows properly, is it possible? Thanks! test

EDIT!

I looked at the answers in the possible duplicate question suggested, but I still do not seem to get it right... I feel like it is almost there though.

Please check my updated MWE below:

\documentclass[xcolor={dvipsnames,table}]{beamer}

%%TABLE
\usepackage{makecell, multirow}
\renewcommand\theadfont{\arraycolor{White}\bfseries}

\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{red!20}}c}
\newcolumntype{B}{>{\columncolor{blue!20}}c}

\mode<presentation> {
    \usetheme[compress]{Singapore}
    \usecolortheme{orchid}
}

\begin{document}

\begin{frame}
    \sffamily
    \arrayrulecolor{white}
    \arrayrulewidth=1pt
    \renewcommand{\arraystretch}{1}
    \rowcolors[\hline]{2}{.!50!White}{}
    \resizebox{\linewidth}{!}{%
        \begin{tabular}{A|A|A|A|A|B|B|B|A}
            \rowcolor{.!50!Black}
            \multicolumn{5}{A|}{\arraycolor{White}\bfseries 14 subjects} &
            \multicolumn{3}{B|}{\arraycolor{White}\bfseries 10 subjects} & \\
            \rowcolor{.!50!Black}
            \multicolumn{3}{A|}{\arraycolor{White} Surface} &
            \multicolumn{2}{A|}{\arraycolor{White} Follicle} &
            \multicolumn{3}{B|}{\arraycolor{White} Surface} &
            \multirow{-2}{*}{\thead{Control}}\\
            No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\\
        \end{tabular}
    }%
\end{frame} 

\end{document}

Which produces:

test2

DaniCee
  • 2,217
  • 1
    As first step: Don't use \multirow{2}... in the first, but \multirow{-2}... in the second line. This way "Control" isn't covered by the effects of \rowcolor. The white line between the cells isn't covered this way. – Skillmon Dec 05 '17 at 09:23
  • 3
    Off-topic: There's definitely no need to load the multicol package. – Mico Dec 05 '17 at 09:23
  • 2
    What should those >{\hsize=\hsize\tabcolsep\arrayrulewidth\relax} instructions do? If I'm not mistaken, removing those doesn't make a difference. – Skillmon Dec 05 '17 at 09:48
  • @Skillmon you are right, those instructions don't do anything, I don't know where I took them from... – DaniCee Dec 06 '17 at 01:58
  • However, using \multirow{-2} in the second line, I still observe the line break, and "Control" isn't aligned vertically in the center of the double cell anymore... – DaniCee Dec 06 '17 at 01:59
  • It is as good vertically centred as it was before. Just with the deviation in the opposite direction that's because of the additional \hline rule width which isn't considered by \multirow. You could solve that with an additional \raisebox{0.5\arrayrulewidth}{...} inside the \multirow. I did say that this doesn't remove the white \hline. For this I don't have a solution. That's why I didn't post an answer. – Skillmon Dec 06 '17 at 08:25
  • unfortunately beamer heavely interfere with hhline, consequently the trick with use of hhline instead of \cline used in https://tex.stackexchange.com/questions/403365/hhline-not-working-with-multirow-and-cellcolor/403395#403395 doesn't work properly. – Zarko Dec 06 '17 at 12:21
  • I had a look at the answers in the possible duplicate (https://tex.stackexchange.com/questions/404872/are-beamer-hhline-and-tablexcolor-incompatible) but I still don't seem to get it right... I feel it's almost there though. Please check my edit. Thanks! – DaniCee Dec 07 '17 at 07:15
  • related bug report: https://github.com/josephwright/beamer/issues/434 – samcarter_is_at_topanswers.xyz Dec 08 '17 at 09:43

2 Answers2

3

like this?

enter image description here

the main problem is composing row colors and coloring of text. replacing them with more elementary approach and consider David Carlisle answer on my question the solution is:

 \documentclass[xcolor={dvipsnames,table}]{beamer}

%%TABLE \usepackage{multirow} \usepackage{hhline} \makeatletter \let\zz\reset@color \def\reset@color{\kern\z@\zz} \makeatother

\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}} \newcolumntype{A}{>{\columncolor{red!20}}c} \newcolumntype{B}{>{\columncolor{blue!20}}c}

\mode<presentation> { \usetheme[compress]{Singapore} \usecolortheme{orchid} }

\begin{document}

\begin{frame} \sffamily \arrayrulewidth=1pt \arrayrulecolor{white} \resizebox{\linewidth}{!}{% \begin{tabular}{A|A|A|A|A|B|B|B|A} \rowcolor{.!50!Black} \multicolumn{5}{A|}{\color{White}\bfseries 14 subjects} & \multicolumn{3}{B|}{\color{White}\bfseries 10 subjects} & \ \hhline{>{\arrayrulecolor{white}}--------% >{\arrayrulecolor{red!20!black!60}}-} \rowcolor{.!50!Black} \arrayrulecolor{white} \multicolumn{3}{A|}{\color{White} Surface} & \multicolumn{2}{A|}{\color{White} Follicle} & \multicolumn{3}{B|}{\color{White} Surface} & \multirow{-2}{*}{\color{white}Control}\ \hline No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\ \end{tabular} }% \end{frame}

\end{document}

Addendum: After almost four year I would for this table use a new package tabularray which better handle rows, columns and cells coloring:

enter image description here

Using it table code is shorter and more clear:

\documentclass{beamer}
\usepackage{tabularray}

\begin{document}

\begin{frame} \frametitle{Table} \centering \sffamily \small \begin{tblr}{colspec={ c }, colsep = 5pt, row{1} = {font=\bfseries, bg=black!80, fg=white}, row{2} = {bg=black!80, fg=white}, row{3} = {bg=red!30, fg=white}, hlines={1pt, fg=white}, vlines={1pt, fg=white}, } \SetCell[c=5]{c} 14 subjects & & & & & \SetCell[c=3]{c} subjects & & & \SetCell[r=2]{c} Control \ \SetCell[c=3]{c} Surface & & & \SetCell[c=2]{c} Follicle & & \SetCell[c=3]{c} Surface & & & \ No les & Non-inf & Inf & Non-inf & Inf & \SetCell{bg=blue7} Cheek & \SetCell{bg=blue7} Fh & \SetCell{bg=blue7} Nose & Mock \ \end{tblr} \end{frame}

\end{document}

Zarko
  • 296,517
0

Here is a way to do that table with {NiceTabular} of nicematrix. You won't have any faint line in the cell "control", whatever PDF viewer you use.

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{nicematrix}

\mode<presentation> { \usetheme[compress]{Singapore} \usecolortheme{orchid} }

\begin{document}

\newcolumntype{A}{>{\columncolor{red!20}}c} \newcolumntype{B}{>{\columncolor{blue!20}}c}

\begin{frame} \begin{center} \sffamily \small \setlength{\tabcolsep}{5pt} \renewcommand{\arraystretch}{1.2} \begin{NiceTabular}{AAAAABBBA}[rules={color=white,width=1pt},hvlines-except-borders,colortbl-like] \CodeBefore \rowcolor{.!50!Black}{1,2} \Body \RowStyle[nb-rows=2,color=white]{} \RowStyle[bold]{} \Block{1-5}{14 subjects} &&&&& \Block{1-3}{10 subjects} &&& \Block{2-1}{Control}\ \Block{1-3}{Surface} &&& \Block{1-2}{Follicle} && \Block{1-3}{Surface} \ No les & Non-inf & Inf & Non-inf & Inf & Cheek & Fh & Nose & Mock\ \end{NiceTabular} \end{center} \end{frame}

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250