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

9
  • 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 5, 2017 at 9:23
  • 3
    Off-topic: There's definitely no need to load the multicol package.
    – Mico
    Dec 5, 2017 at 9: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 5, 2017 at 9:48
  • @Skillmon you are right, those instructions don't do anything, I don't know where I took them from...
    – DaniCee
    Dec 6, 2017 at 1: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 6, 2017 at 1:59

2 Answers 2

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}
2
  • I guess the faint lines are a viewer problem. I can reproduce them with mac preview but with adobe reader everything looks fine. Dec 8, 2017 at 9:42
  • For mac preview this seems to be an anti-aliasing problem. It goes away if "smooth text and line art" is not selected. Dec 8, 2017 at 9:47
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .