Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semi-transparent figures in beamer (pdflatex)

I am attempting to use overlays with figures to save myself from creating a different image for each slide. The overlay works with any text I include, but not with the figures. For example:

\setbeamercovered{dynamic}
\begin{figure}\resizebox{10.0cm}{!}{
        \includegraphics{problem-a.pdf}
        Test A
        \pause
        \includegraphics{problem-b.pdf}
        Test B
        \pause
        \includegraphics{problem-c.pdf}
        Test C
}\end{figure}

Results in the text "Test B" and "Test C" being shaded on the first slide, but the figures corresponding to "problem-b" and "problem-c" are not shaded.

like image 305
Compholio Avatar asked Oct 15 '09 20:10

Compholio


2 Answers

For anyone that stumbles upon this, the best thing I've found so far is to use tikz and setup a custom transparency mode:

\gdef\transparent@value{100}
\newcommand{\getbeamertrans}{
    \transparent@value/100
}
\newcommand{\set@transparent}[1]{\gdef\transparent@value{#1}}
\def\opaquenessCustom#1{%
\only<1->{%
  \beamer@actions{%
    \set@transparent{#1}%
    \expandafter\xdef\csname beamer@oldcolorhook%
    \the\beamer@coveringdepth\endcsname{\beamer@colorhook}%
    \expandafter\xdef\csname beamer@oldpgfextension%
    \the\beamer@coveringdepth\endcsname{\beamer@pgfextension}%
    {\globalcolorstrue\colorlet{beamer@freeze\the\beamer@coveringdepth}{bg}}%
    \xdef\beamer@colorhook{!#1!beamer@freeze%
      \the\beamer@coveringdepth\beamer@colorhook}%
    \gdef\beamer@pgfextension{!#1opaque}%
    \color{.}%
  }%
  {%
    \set@transparent{100}%
    \xdef\beamer@colorhook{\csname beamer@oldcolorhook%
      \the\beamer@coveringdepth\endcsname}%
    \xdef\beamer@pgfextension{\csname beamer@oldpgfextension%
      \the\beamer@coveringdepth\endcsname}%
    \color{.}%
  }}%
}%
\define@key{beamer@mixin}{transparent}[15]{%
    \def\beamer@uncoverbeforeactions{\ignorespaces\opaquenessCustom{#1}}%
    \def\beamer@uncoverafteractions{\ignorespaces\opaquenessCustom{#1}}%
}
\newcommand{\BeamerGraphic}[1]{%
    \begin{tikzpicture}%
        {\node[opacity=\getbeamertrans] {\includegraphics{#1}};}%
    \end{tikzpicture}%
}
like image 177
Compholio Avatar answered Oct 06 '22 15:10

Compholio


Another approach could be to temporarily cover the image with a semi-transparent shape:

\documentclass{beamer}
\usepackage{tikz}
\setbeamercovered{dynamic}

\begin{document}

\begin{frame}

\begin{figure}
    \includegraphics[width=2cm,page=1]{example-image-duck}
    Test A
    \pause
    \begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (B) at (4,0) {\includegraphics[width=2cm,page=2]{example-image-duck}};
    \only<1>{%
        \fill [draw=none, fill=white, fill opacity=0.7] (B.north west) -- (B.north east) -- (B.south east) -- (B.south west) -- (B.north west) -- cycle;
    }
    \end{tikzpicture}
    Test B
    \pause  
     \begin{tikzpicture}
        \node[anchor=south west,inner sep=0] (B) at (4,0) {\includegraphics[width=2cm,page=3]{example-image-duck}};
        \only<1-2>{%
            \fill [draw=none, fill=white, fill opacity=0.7] (B.north west) -- (B.north east) -- (B.south east) -- (B.south west) -- (B.north west) -- cycle;
        }
     \end{tikzpicture}  
    Test C
\end{figure}
\end{frame}

\end{document}

enter image description here

like image 36
samcarter_is_at_topanswers.xyz Avatar answered Oct 06 '22 16:10

samcarter_is_at_topanswers.xyz