# Tikzpicture highlight on matrix in different slides

I am new to latex but I have to make a presentation in university with it (or more I want to do the presentation in LaTeX). But I am struggling with the package tikz.

1. So my first question is regarding the on statement which can not handle something like <1-3, 5-6>, which is possible like in only statements. Is there a work around?

2. Second question is about the highlight style is it possible to set different styles on different slides like highlight text on=<1-3> and something else, text on=<5-6>?

Here is my MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles, matrix}
\begin{document}
\begin{frame}
\begin{tikzpicture}[
background default text=black,
highlight/.style={
background text=blue,
},
]
\matrix [matrix of nodes, ampersand replacement=\&]{
|[highlight, text on=<1->]| . \& |[highlight, text on=<2->]| X \\
. \&  X\\
};
\end{tikzpicture}
\end{frame}
\end{document}


I don't know if it's possible using the built-in capabilities of the overlay-beamer-styles library, but I can achieve this using the accepted answer from How to make beamer overlays with Tikz node:

\tikzset{onslide/.code args={<#1>#2}{%
\only<#1>{\pgfkeysalso{#2}}
}}


creates the possibility of usage like

onslide=<1-2>highlight


to apply the highlight style for overlays 1 and 2. These onslide= constructs are stackable, as shown in the example below.

The definition of \overlaynumber is from Accessing the current overlay number in beamer and is just used for this example to display the current overlay number for illustration purposes.

As mentioned in comments here and at Matthew's answer, if the overlay specification contains commas, the whole construct must be encapsulated in curly braces. (Illustrated with onslide={<4,6-8>cyan} here.)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles, matrix}

\makeatletter % https://tex.stackexchange.com/a/55066/21344
\newcommand*{\overlaynumber}{\number\beamer@slideinframe}
\makeatother

\tikzset{onslide/.code args={<#1>#2}{%
\only<#1>{\pgfkeysalso{#2}}
}} % https://tex.stackexchange.com/a/6155/21344

\begin{document}
\begin{frame}
\begin{tikzpicture}[
background default text=black,
highlight/.style={
background text=blue,
},
laterhilite/.style={
background text=red,
},
]
\matrix [matrix of nodes, ampersand replacement=\&]{
|[highlight, text on=<{1-}>]| . \&
|[onslide=<1-2>highlight,
onslide=<3->laterhilite,
onslide={<4,6-8>cyan},
]|   X\\
. \&  X\\
\overlaynumber \&  \\
};
\end{tikzpicture}
\end{frame}
\end{document}


• You may use <1-2>highlight instead of <1-2>{highlight} (and so on...). The arguments of .code args are delimited (by the comma). – Paul Gaborit Jan 20 '15 at 0:06