2

I am creating slides with overlays in Beamer, using TiKZ to create a figure consisting mainly of text nodes. The idea is that different parts of the figure are highlighted on each slide. Initially it all appears in a light gray (I'm using "seagull" colours with a white background), and on each slide a different part of the figure is shown in full colour.

I've achieved this by basically drawing the figure twice: once in light gray, and then drawing it again using a sequence of "onslide" commands. However, what I'd like is for text in a node to appear as bold face when it appears in colour. Here is an MWE:

\documentclass{beamer}

\usepackage{tikz}

\title{A test} 
\author{Me} 
\date{\today}

\begin{document} 

\begin{frame}   
  \maketitle 
\end{frame}

\begin{frame}{This is the test slide}

  \begin{tikzpicture}[remember picture,overlay,color=lightgray]
    \draw (current page.south west)++(1,1) coordinate (SW);
    \draw (SW)++(2,1) node {First bit of text};
    \draw (SW)++(4,3.5) node {Second bit of text};
    \draw (SW)++(6,6) node {Third and final text};
    \onslide<2>{\draw[color=blue] (SW)++(2,1) node {First bit of text};}
    \onslide<3>{\draw[color=blue] (SW)++(4,3.5) node {Second bit of text};}
    \onslide<4>{\draw[color=blue] (SW)++(6,6) node {Third and final  text};}     
  \end{tikzpicture}    
\end{frame}

\end{document}

Now there may well be an easier and more natural way of doing this; on the other hand it means I can position text wherever I want.

If I include a text = \bfseries in the second part of the above, then it seems to stick, and the lightgray text is also bold, which I don't want. So - any ideas on how text will appear in a color and bold, and then go back to lightgray and normal when it's not highlighted?

  • To clearify: You want to highlight each text separately, first it is lightgray, than blue and bold and afterwards appears in lightgray again? Well, if you just overprint with \textbf{} the lightgray will still be there underneath the blue text, with a smaller width. – user31729 Jun 21 '14 at 5:27
2

Is this what you want to achieve?

Draw the lightgray parts only on a specified number of slides using the \only<frame_number> command and afterwards use \onlide<2> (or another frame number` to draw the text in other font/color etc.

\documentclass{beamer}

\usepackage{tikz}

\title{A test} 
\author{Me} 
\date{\today}

\begin{document} 

\begin{frame}   
  \maketitle 
\end{frame}

\begin{frame}{This is the test slide}

  \begin{tikzpicture}[remember picture,overlay,color=red]
    \draw (current page.south west)++(1,1) coordinate (SW);
    \only<1,3-4>{\draw (SW)++(2,1) node {First bit of text};}
    \only<1-2,4>{\draw (SW)++(4,3.5) node {Second bit of text};}
    \only<1-3>  {\draw (SW)++(6,6) node {Third and final text}};
    \only<2>{\draw[color=blue] (SW)++(2,1) node {\textbf{First bit of text}};}
    \only<3>{\draw[color=blue] (SW)++(4,3.5) node {\textbf{Second bit of text}};}
    \only<4>{\draw[color=blue] (SW)++(6,6) node {\textbf{Third and final  text}};}     
  \end{tikzpicture}    
\end{frame}

\end{document}

I changed from lightgray to red just for the snapshot, because lightgray is hard to recognize in a screenshot.

enter image description here

  • That's perfect: clearly only is the answer to my query. Thanks very much! – Alasdair Jun 21 '14 at 6:58
2

Instead of drawing the content twice (which involves difficult to maintain code duplication), I suggest to just change the color and font attributes on the specific slides. In the following the onslide=<overlay spec>{key=value, key=value} TikZ style provides just that:

\documentclass{beamer}

\usepackage{tikz}

% TikZ stile to apply keys only on specific beamer overlays
% onslide=<overlay spec>{key=value, key=value, ...}
\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}}%
}}



\title{A test} 
\author{Me} 
\date{\today}

\begin{document} 

\begin{frame}   
  \maketitle 
\end{frame}

\begin{frame}{This is the test slide}

  \begin{tikzpicture}[remember picture,overlay,color=red]
    \draw (current page.south west)++(1,1) coordinate (SW);
    \draw[onslide=<2>{color=blue, font=\bfseries}] (SW)++(2,1) node {First bit of text};
    \draw[onslide=<3>{color=blue, font=\bfseries}] (SW)++(4,3.5) node {Second bit of text};
    \draw[onslide=<4>{color=blue, font=\bfseries}] (SW)++(6,6) node {Third and final text};
  \end{tikzpicture}    
\end{frame}

\end{document}

The code may further be improved by defining an own style for the highlighting, so that you can easily change that later or reuse it on other frames:

\tikzset{highlight/.style={color=blue, font=\bfseries}} 

\begin{tikzpicture}[remember picture,overlay,color=red]
  \draw (current page.south west)++(1,1) coordinate (SW);
  \draw[onslide=<2>{highlight}] (SW)++(2,1) node {First bit of text};
  \draw[onslide=<3>{highlight}] (SW)++(4,3.5) node {Second bit of text};
  \draw[onslide=<4>{highlight}] (SW)++(6,6) node {Third and final text};
\end{tikzpicture}

Further References:

1

Better don't change font when highlighting, unless it is just a letter or single symbol. The widths and spacings change, which will led to labels wiggling around. To distracting. Better use color change only, say a (dark) gray vs red.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.