5

I have a fancy table in the following MWE, and for the life of me I cannot remove the cell in the lower left corner, and I cannot split lines within cells (I want to split "Ovulation date" and "Poor barrier" in two lines). Check the Beamer MWE below:

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

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

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

\begin{document}

\begin{frame}
    \sffamily
    \arrayrulecolor{white}
    \arrayrulewidth=1pt
    \renewcommand{\arraystretch}{1}
    \rowcolors[\hline]{2}{.!50!White}{}
    \begin{tabular}{@{}A|B|A|B|A}%remove indent
        \rowcolor{.!50!Black}
        \arraycolor{White}\bfseries {\tiny Subject} & \arraycolor{White}\bfseries {\tiny Dry} & \arraycolor{White}\bfseries {\tiny Ovulation date} & \arraycolor{White}\bfseries {\tiny Oiliest} & \arraycolor{White}\bfseries {\tiny Poor barrier}\\
        \bfseries {\tiny 2007} & {\tiny 8, 36} & {\tiny 14} & {\tiny 22} & {\tiny 26}\\
        & \bfseries {\tiny I - DR} & \bfseries {\tiny II - OP} & \bfseries {\tiny III - OL} & \bfseries {\tiny IV - PB}
    \end{tabular}
\end{frame} 

\end{document}

test

With this kind of table, I would need to learn how to:

  • Remove cells

  • Split lines within cells

0

1 Answer 1

8

Something like this? (Note that I've removed all \tiny directives.)

enter image description here

(Insert the instruction \renewcommand{\tabularxcolumn}[1]{m{#1}} after loading tabularx if the header cells need to be centered vertically rather than top-aligned.)

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

\usepackage{tabularx}
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{A}{>{\columncolor{red!20}}C}
\newcolumntype{B}{>{\columncolor{blue!20}}C}

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

\begin{document}
\begin{frame}
    \arrayrulecolor{white}
    \setlength{\arrayrulewidth}{1.5pt}
    \setlength{\extrarowheight}{2pt}
    \begin{tabularx}{\textwidth}{A|B|A|B|A}
        \rowcolor{.!50!Black}
        \arraycolor{White}\bfseries Subject &
        \arraycolor{White}\bfseries Dry & 
        \arraycolor{White}\bfseries Ovulation date &
        \arraycolor{White}\bfseries Oiliest &
        \arraycolor{White}\bfseries Poor barrier \\
        \hline
        \bfseries 2007 &  8, 36 & 14 & 22 & 26 \\
        \hline
        \multicolumn{1}{c}{\cellcolor{white}} % for a "blank" cell
        & \bfseries I - DR 
        & \bfseries II - OP 
        & \bfseries III - OL 
        & \bfseries IV - PB \\
    \end{tabularx}
\end{frame}
\end{document}
7
  • Thanks it works awesome! But I don't really understand how the line breaks work... for cases with longer texts in a cell, is there a way to specify the breaks wherever I want?
    – DaniCee
    Dec 5, 2017 at 8:36
  • @DaniCee - The X column type performs automatic line breaking — if needed. (For the example at hand, line breaking was needed in 2 of the 5 header cells.) The table you’ve designed isn’t really suitable for longer blocks of text, is it? Selecting the optimal linebreak points in a longer block of text will likely require some fine-tuning by hand.
    – Mico
    Dec 5, 2017 at 9:04
  • 1
    Aside: I just noticed that this answer was the 4,500th answer I've posted on TeX.SE since joining the site in mid-2011. It's a great community, for sure. I feel privileged to be able to make some contributions. :-)
    – Mico
    Dec 5, 2017 at 9:19
  • 3
    Congrats on your 4,500th answer!!
    – DaniCee
    Dec 5, 2017 at 9:21
  • 2
    @DaniCee: To break the contents of a X or p cell at a specific point, just tyst type \newline (or define a shortcut like \nl).
    – Bernard
    Dec 5, 2017 at 10:06

You must log in to answer this question.

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