1

I am having trouble with updating labels of tikz blocks in a beamer presentation. So far I have been using \onslide to update the block size and location from code in this answer. For the label text, \onslide shifts things up and down (as expected). With \only the label text shifts horizontally a little?

\documentclass[pd,xcolor={dvipsnames}]{beamer}
\usetheme{Frankfurt}
\usepackage[absolute,overlay]{textpos}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,positioning,patterns}
\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}} % \pgfkeysalso doesn't change the path
}}

\begin{document}
\begin{frame}

\centering
\tikzstyle{blocka} = [text width=3.0em, text centered, rectangle, rounded corners, fill, fill=red]
\tikzstyle{every node}=[font=\boldmath,color=white]
\tikzstyle{ann} = [draw=none,fill=white,rounded corners]

\begin{tikzpicture}
\node[blocka,
onslide=<1-2>{minimum height=10.00em},
onslide=<3-4>{minimum height=8.00em}, 
onslide=<5>{minimum height=7.67em},
onslide=<2-3>{pattern=crosshatch,pattern color=red}] (Aa1) {
\only<1>{$100$} 
\only<2-3>{ } 
\only<4>{$80$}
\only<5->{$76.7$}
%\onslide<1>{$100$}, 
%\onslide<2-3>{ }, 
%\onslide<4>{$80$},
%\onslide<5->{$76.7$};
};
\node[ann, left=0.25em of Aa1.180, color=red, fill=white] {A};

\end{tikzpicture}
\end{frame}

\end{document}
guyabel
  • 427
  • 1
    Put a % after each \only<>{} and you are ready to go. Right now, you are inserting some spurious white spaces by hitting enter after each line. (For future MWEs please try to minimize as much as you can.Thanks) – LaRiFaRi Jun 16 '15 at 11:33
  • Or maybe you need to specify text width big enough to contain the widest text? – cfr Jun 17 '15 at 02:50

1 Answers1

1

The \only<>{} command should be followed by a %-sign if you which to hit enter for a new line. A new line is interpreted as a white space in LaTeX. This white space was set in front of your numbers and therefore moved them out of the centre.

% arara: pdflatex

\documentclass{beamer}
\usetheme{Frankfurt}
\usepackage{tikz}
\usetikzlibrary{positioning,patterns}
\tikzset{%
    ,onslide/.code args={<#1>#2}{\only<#1>{\pgfkeysalso{#2}}}
    ,every node/.style={font=\boldmath,color=white}
    ,blocka/.style={text width=3.0em, text centered, rectangle, rounded corners, fill, fill=red}
    ,ann/.style={draw=none,fill=white,rounded corners}  
    }

\begin{document}
\begin{frame}
    \begin{center}
        \begin{tikzpicture}
        \node[blocka,
            onslide=<1-2>{minimum height=10.00em},
            onslide=<3-4>{minimum height=8.00em}, 
            onslide=<5>{minimum height=7.67em},
            onslide=<2-3>{pattern=crosshatch,pattern color=red}] (Aa1) {%
                \only<1>{$100$}% <= this one centeres the first slide 
                \only<2-3>{ }% <= this one centeres the fourth slide 
                \only<4>{$80$}% <= this one centeres the fifth slide
                \only<5->{$76.7$}%
                };
        \node[ann, left=0.25em of Aa1.180, color=red, fill=white] {A};          
        \end{tikzpicture}   
    \end{center}
\end{frame}
\end{document}
LaRiFaRi
  • 43,807