2

I want to achieve the same result as for the question: Tikz animated figure in Beamer

The difference in my case is, that I use labels in my nodes. For nodes there is already a solution in the comment by @kmundnic: Tikz animated figure in Beamer

But in my special case I have newlines in the labels, which results in the error:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.16 \end{frame}

?

My MWE to reproduce the error is:

\documentclass[tikz]{beamer}
\usepackage{tikz}

\tikzset{ invisible/.style={opacity=0,prefix after command={\pgfextra{\tikzset{every label/.style={opacity=0}}}}}, visible on/.style={alt={#1{}{invisible}}}, alt/.code args={<#1>#2#3}{% \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path }, } \begin{document} \begin{frame} \begin{tikzpicture}[every label/.style={align=center}] \path (1,1) node[draw, shape=circle, text width=2.2cm, visible on=<2->, label=center:{Label\new Line}] (LODL2) {}; \end{tikzpicture} \end{frame} \end{document}

If you just leave out the \\ it will compile.

Edit:* added every label/.style={align=center} to tikzpicture which is needed to compile the MWE without the animation part.

Edit2:* putting the label into the node, so far is no solution, as the amount of text make the node bigger:

  \path (1,1) node[draw, shape=circle, text width=2.2cm, align=center, label=center:{Label\\new Line}] (LODL1) {};
  \path (4,1) node[draw, shape=circle, text width=2.2cm, visible on=<2->, align=center, label=center:{}] (LODL2) {Label\\new Line};
  \path (1,1) node[draw, shape=circle, text width=2.2cm, visible on=<3->, align=center, label=center:{}] (LODL2) {Label\\new Line};

In this image, first the node is drawn as I want it at (1,1), then two nodes are drawn at (4,1) and (1,1) with the label in the node. As one can see the second and third node is bigger than the first node. The more text, the bigger the circle.

enter image description here

white_gecko
  • 2,101

2 Answers2

3

This works if you put the text into the node itself without the need for the prefix after command command.

\documentclass[tikz]{beamer}
\usepackage{tikz}

\tikzset{ invisible/.style={opacity=0,%prefix after command={\pgfextra{\tikzset{every label/.style={opacity=0}}}} }, visible on/.style={alt={#1{}{invisible}}}, alt/.code args={<#1>#2#3}{% \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path }, } \begin{document} \begin{frame} \begin{tikzpicture}[] \path (1,1) node[draw, shape=circle, text width=2.2cm, visible on=<2->,align=center] (LODL2) {Label\ new Line}; \end{tikzpicture} \end{frame} \end{document}

AndréC
  • 24,137
  • Thank you for your answer. But this does not solve the problem. When I add the label into the node itself the circle gets bigger, when I add more text. But I want to keep the size of the circle, as it is independent of the amount of text in the label. – white_gecko Jun 27 '20 at 21:29
  • I don't understand what you mean by "gets bigger" since the first slide doesn't show any circles. What may be making the circle bigger is the text width=2.2cm parameter you added to the code. – AndréC Jun 27 '20 at 22:10
  • I've tried to illustrate the issue with the label in the node in my second edit. – white_gecko Jun 28 '20 at 12:26
2

Using two nodes and \onslide

\documentclass{beamer}
\usepackage{tikz}

\begin{document} \begin{frame} \begin{tikzpicture}[every label/.style={align=center}]

\path (1,1) node[draw, shape=circle, text width=2.2cm] (LODL2) {};

\onslide<2>{ \path (1,1) node[ shape=circle, text width=2.2cm, label=center:{Label\new Line}] {}; } \end{tikzpicture} \end{frame} \end{document}

enter image description here

vi pa
  • 3,394
  • This brought me to the solution, there is no need for visible on= i just hide/reveal the nodes with \uncover{} which works great. :-) – white_gecko Jun 28 '20 at 12:33