This is due to an unfortunate interaction between how overprint
works and the center
environment. Because the center
environment is in force when overprint
is figuring out which text to use, the text gains some extra horizontal space (to centre it). But when overprint
sets the text, it modifies it in such a way that TeX adds yet more space to centre it again. Net result being that the text gets shoved too far over to the right. Thanks to David Carlisle and Herbert, I can offer two ways to "cancel" the effect. Both get rid of the centre
effect when the overprint
environment is doing its stuff.
Note that due to the way overprint
works, to get the contents centred, you have to add in \centering
to each piece. There's no other way to do that. I've assumed, in the below, that that is what you want to happen.
\documentclass[transparent]{beamer}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}
\makeatletter
\def\normaljustify{%
\let\\\@centercr
\rightskip\z@skip
\leftskip\z@skip%
\parfillskip=0pt plus 1.0fil\relax
}
\makeatother
\begin{document}
\begin{frame}%
\begin{center}
\begin{tikzpicture}[every node/.style={draw}]
\onslide<+->{\node(a){Herbert's code};}
\onslide<+->{\node(b)[below=of a,align=center]{%
\normaljustify
\begin{overprint}[4cm]
\onslide<+>
\centering
$a=b$
\onslide<+>
\centering
$b=c$
\onslide<+>
\centering
$c=d$
\end{overprint}
};}
\node(c)[below=of b]{test2};
\end{tikzpicture}
\begin{tikzpicture}[every node/.style={draw}]
\onslide<+->{\node(a){David Carlisle's code};}
\onslide<+->{\node(b)[below=of a,align=center]{%
\begin{minipage}{\textwidth}%
\begin{overprint}[4cm]
\onslide<+>
\centering
$a=b$
\onslide<+>
\centering
$b=c$
\onslide<+>
\centering
$c=d$
\end{overprint}%
\end{minipage}
};}
\node(c)[below=of b]{test2};
\end{tikzpicture}
\end{center}
\end{frame}%
\end{document}
I'm not sure which of the two to prefer. One thing to note about David's method (with the additional minipage
) is that if you put anything "normal" (such as bare text) inside that minipage then it will have width \textwidth
which is not desirable.
![overprint and centre sorted out](https://i.stack.imgur.com/vmyzc.png)
The simplest way IMHO is to typeset the inner tikzpicture
in a savebox outside the other tikzpicture
and then use the box inside the node.
This way no settings of the parent tikzpicture
will be picked up, because the inner one is already rendered.
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newsavebox\mybox
\begin{document}
\begin{lrbox}{\mybox}
\begin{tikzpicture}
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\draw [draw,->,ultra thick] (0,0.0) -- (0,1.5);
\draw [draw,->,ultra thick] (0,0.0) -- (2.5,0);
\draw [fill=blue!20!white,ultra thick,overlay] (0.2,0) ..controls
(0.5,2.2) and (1,0.1) .. (2,0);
\end{tikzpicture}
\end{lrbox}
\begin{tikzpicture}[node distance=2em]
\node(pdf){\usebox\mybox};
\node [rectangle,draw, right=of pdf] (cfd) {Nonlinear Flow Solution};
\path[draw,->] (pdf) -- (cfd);
\end{tikzpicture}
\end{document}
If you want to do this using a macro:
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newsavebox\mybox
\begin{lrbox}{\mybox}
\normalfont% to ensure that the font is fully set up
\begin{tikzpicture}
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\draw [draw,->,ultra thick] (0,0.0) -- (0,1.5);
\draw [draw,->,ultra thick] (0,0.0) -- (2.5,0);
\draw [fill=blue!20!white,ultra thick,overlay] (0.2,0) ..controls
(0.5,2.2) and (1,0.1) .. (2,0);
\end{tikzpicture}
\end{lrbox}
\newcommand\mypdfimage{\usebox\mybox}
\begin{document}
\begin{tikzpicture}[node distance=2em]
\node(pdf){\mypdfimage};
\node [rectangle,draw, right=of pdf] (cfd) {Nonlinear Flow Solution};
\path[draw,->] (pdf) -- (cfd);
\end{tikzpicture}
And again:
\begin{tikzpicture}[node distance=2em]
\node(pdf){\mypdfimage};
% [..]
\end{tikzpicture}
\end{document}
But here the macro is just a short-cut, you can use \usebox\mybox
directly if you don't mind.
Best Answer
The problem with your code is that the
\tikz
command itself is not overlay-aware. (I think that it would be quite difficult to make it so.) So the\tikz
stuff is getting executed on every slide, but theyyy
node doesn't exist until the second slide so it doesn't know what to do with it. If you shift the<2>
to the\draw
instead then it works.