18

I'm creating a beamer presentation, in which I use TikZ.

I am making a figure, on which I would like to highlight something (using \only<> command). My figure contains an ellipse that is decorated with random steps:

...
\node[ellipse,minimum width=1cm,black!30,decorate,decoration={random steps,segment length=0.2cm,amplitude=.1cm}] {}; 
\only<1>{
\node (n) at (0,0) {A};
}
\only<2>{
\node (n) at (0,0) {B};
}

The ellipse is rendered in differenlty. How can I make it to render the same? or what other decoration can I use to get a similar effect to random steps?

jfu
  • 283
  • 1
  • 5

1 Answers1

24

The problem was due to the seed: if you add \pgfmathsetseed{<integer number>} before the first \node the seed used to generate random numbers is reset in each slide, forcing the path to be the same.

Here's a complete example (I took some liberty with the size of the shape):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,decorations,decorations.pathmorphing}

\begin{document}

\begin{frame}{Title frame}
\begin{tikzpicture}
\pgfmathsetseed{23654}
\node[thick,draw,ellipse,minimum width=3cm,minimum height=1.5cm,black!30,decorate,decoration={random steps,segment length=0.3cm,amplitude=.3cm}] {}; 
\only<1>{
\node (n) at (0,0) {A};
}
\only<2>{
\node (n) at (0,0) {B};
}
\end{tikzpicture}
\end{frame}

\end{document}

Result:

enter image description here

  • Glad of having helped you. I would courteously suggest for the future to upvote all answers you find useful, including those to others' questions and to check/accept the best answers to your own questions by clicking the green tick on the left-hand side of the answer. – Claudio Fiandrino Sep 07 '12 at 15:57
  • I'd love to upvote, but I don't have enough reputation yet :) – jfu Sep 07 '12 at 16:07
  • No problems: my comment should be intended as good recommendation for new users. :) – Claudio Fiandrino Sep 07 '12 at 16:10
  • @ClaudioFiandrino How to get a closed curve? – Sigur Apr 01 '19 at 18:26
  • 1
    @Sigur: for that you have to operate on the decoration, try to fix the amplitude, segment length, (the path if you don't use a node construction). – Claudio Fiandrino Apr 02 '19 at 10:08