2

I am trying to draw a simple "array" data structure in Beamer using tabular. I would like to color some of the cells blue. Here is my M(N)WE.

\documentclass{beamer}

\usepackage[table]{xcolor}
\begin{document}

\begin{frame}
\frametitle{test}

\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\cellcolor{blue!25}A&
\cellcolor{blue!25}B&
\cellcolor{blue!25}C&
B&
A&
B&
C\\
\hline
\end{tabular}
\end{frame}

\end{document}

This doesn't compile. How should it be done?

The first problem is

! LaTeX Error: Option clash for package xcolor.

0

1 Answer 1

11

The "problem" is, that beamer automatically loads the xcolor-package. But luckily you can simply pass your desired option by using \documentclass[xcolor=table]{beamer}

enter image description here

\documentclass[xcolor=table]{beamer}

\begin{document}

\begin{frame}
\frametitle{test}

\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\cellcolor{blue!25}A&
\cellcolor{blue!25}B&
\cellcolor{blue!25}C&
B&
A&
B&
C\\
\hline
\end{tabular}
\end{frame}

\end{document}

Alternatively, you could use the tabularray package:

\documentclass{beamer}

\usepackage{tabularray}

\begin{document}

\begin{frame}
\frametitle{test}

\begin{tblr}{
  colspec={|c|c|c|c|c|c|c|},
  hlines,vlines,
  cell{1}{1-3}={bg=blue!25}
}
A & B & C & B & A & B & C\\
\end{tblr}
\end{frame}

\end{document}

enter image description here

12
  • Thanks! I now get only "LaTeX Font Warning: Font shape `OT1/cmss/m/n' in size <4> not available (Font) size <5> substituted on input line 18."
    – Simd
    Jun 5, 2014 at 16:36
  • Is it just an illusion or are the letter positions high in their cells? They don't seem to be in the middle.
    – Simd
    Jun 5, 2014 at 16:40
  • Concerning your font size problem: For me, this warning can be ignored, but if you want to get rid of it, have a look at texblog.net/latex-archive/uncategorized/beamer-warnings which basically suggest to include \let\Tiny=\tiny in the preamble Jun 5, 2014 at 16:41
  • 1
    I am not sure it is an illusion in fact. I zoomed in a long way and there is clearly more space below than above the letters.
    – Simd
    Jun 5, 2014 at 16:52
  • care to post a screenshot? or even open a new question? Jun 5, 2014 at 16:56

You must log in to answer this question.

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