How to Use Beamer’s \visible with \cellcolor
At a glance
- 1. Separate the effects
Use \visible for cell content and an overlay test for the cell background.
- 2. Choose both fills
Specify the background color on every overlay, including the overlays before the highlight.
- 3. Check the table setup
Enable xcolor’s table support so \cellcolor is available.
In a Beamer table, \visible and \cellcolor affect different things. \visible controls whether content can be seen while preserving its space in the layout. \cellcolor paints the cell background. If you put \cellcolor inside \visible, the cell’s fill may still show on overlays where you expected it to be hidden.
The reliable approach is to control the background with an overlay-aware command, and use \visible separately for the content.
Why \visible may not hide a cell fill
Beamer’s \visible<...>{...} is useful when an object should be absent visually on some slides but should still occupy space. That prevents nearby material from shifting when the object appears.
A cell background is not ordinary text, though. \cellcolor sets up coloring for the table cell, rather than simply producing visible characters. Hiding the material that invokes it with \visible does not reliably hide the resulting background. In other words, \visible is not a general-purpose switch for every visual effect inside its argument.
Set the background and content separately
Use \alt to choose the cell fill on each overlay. In the example below, the second cell is white on overlay 1 and yellow from overlay 2 onward. Its text is invisible on overlay 1 but keeps its space in the table.
\documentclass[xcolor=table]{beamer}
\begin{document}
\begin{frame}{Conditional cell background}
\begin{tabular}{|c|c|}
\hline
Item & \alt<2->{\cellcolor{yellow}}{\cellcolor{white}}%
\visible<2->{Highlighted} \\
\hline
\end{tabular}
\end{frame}
\end{document}
The xcolor=table class option enables table-color support for \cellcolor. The \alt command selects the yellow fill on overlay 2 and later, and the white fill on overlay 1. \visible<2->{Highlighted} reveals the text from overlay 2 onward while reserving its space beforehand.
The explicit white fill is suitable for a white table background. If your slide design uses a different background or a colored default cell, replace white with the fill you want on the earlier overlays.
If only the fill should change
When the cell text should always be visible, omit \visible and condition just the fill:
\alt<2->{\cellcolor{yellow}}{\cellcolor{white}}Always visible text
This is often the simplest fix. It also makes the intent clear: the cell remains present, but its background changes at the specified overlay.
Common mistakes
- Wrapping the whole cell in
\visible: This controls the visibility of its contents, not necessarily the background effect created by\cellcolor. - Leaving the earlier overlay unspecified: If the background must be uncolored before the highlight, explicitly choose the earlier fill. Otherwise an existing or default fill may remain visible.
- Using
\onlywhen the table must not move:\onlyremoves its material on inactive overlays, so it does not reserve space. Use\visiblewhen preserving the content’s space matters. - Forgetting table-color support: If
\cellcoloris undefined or unavailable, enable table support, as in\documentclass[xcolor=table]{beamer}.
For a full row or several cells, apply the same conditional-fill pattern to each cell that needs to change. Beamer overlays are typeset as separate slide states, so check both the earlier and later overlays when you compile the presentation.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.