4

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

15

Update 2024:

Thanks to changes in recent latex versions, using \usepackage[table]{xcolor} should now work fine and the below answer should no longer be necessary.

Original answer:

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={ccccccc},
  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

16
  • 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
    Commented 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
    Commented Jun 5, 2014 at 16:40
  • 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
    Commented Jun 5, 2014 at 16:52
  • 1
    @Simd ^^^ just use stretch=0
    – CarLaTeX
    Commented May 15 at 12:04
  • 1
    for vertical lines in tblr is sufficient to us one instruction for the, so you can delete vlines or vertical bars | in colspec instructions.
    – Zarko
    Commented May 15 at 13:34

You must log in to answer this question.

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