Semi-transparent figures in beamer (pdflatex)

19,072

Solution 1

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}%
}

Solution 2

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

Share:
19,072
Compholio
Author by

Compholio

Updated on June 04, 2022

Comments

  • Compholio
    Compholio almost 2 years

    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.

  • greschd
    greschd about 9 years
    I realize this is an old question, but I can't get this to work... what packages did you include?
  • Compholio
    Compholio about 9 years
    @greschd: According to my records: subfigure, tikz, textcomp
  • Compholio
    Compholio about 5 years
    this only works properly with a solid background, adjusting the opacity works even if you have a gradient (or other custom) background