11

I have a similar problem to this one, only I'm using tikz-cd instead of tikz.

Here is a minimal example:

\begin{frame}
\begin{tikzcd}[ampersand replacement=\&]
1{\uncover<2->{\arrow{r}}}\&2
\end{tikzcd}
\end{frame}

This will have two slides, both having the arrow. Removing the {...} will lead to an Error:

Giving up on this path. Did you forget a semicolon? 

Using \only instead of \uncover does work, but does move things in bigger diagrams, which I don't want.

Is there a workaround without converting all my tikz-cd diagrams into tikzpictures?

1 Answer 1

14

Use the visible on style:

\documentclass{beamer}
\usepackage{tikz-cd}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  }
}

\begin{document}

\begin{frame}
\begin{tikzcd}[ampersand replacement=\&]
1 \arrow[visible on=<2->,r]\arrow[visible on=<3>,d] \& 2\arrow[visible on=<2->,d] \\
3 \arrow[visible on=<3>,r] \& 4 
\end{tikzcd}
\end{frame}

\end{document}

enter image description here

4
  • 3
    How can you apply this visibility to the nodes? That is, to make them appear together with each relevant arrow? Commented Jul 26, 2019 at 21:06
  • 6
    I found the answer to my question: you can pass key-value pairs to nodes using the syntax |[key=value]| before the node. Thus, node 3 can be shown from slide three onwards with |[visible on=<3->]| 3. Commented Jul 28, 2019 at 12:01
  • @Tom-Verhoeff, I can't believe that works! Thanks for answering your own question publicly.
    – Timtro
    Commented Jan 25, 2020 at 5:21
  • \uncover itself also works fine for nodes (but make sure to surround in curly brackets, e.g. {\uncover<3->{1}}).
    – varkor
    Commented Jun 10 at 10:17

You must log in to answer this question.

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