12

I am writing a presentation in beamer. I have a background image that I have included with \setbeamertemplate{background canvas}{...}. Within a regular slide, I now would like to create a rectangle that fades from a color to fully transparent in Tikz. If I create a rectangle with fading, i.e. \tikz{\fill[left color=RED,right color=transparent] (0,0) rectangle (\linewidth,1.5em);} It creates the rectangle, but rather than being see-through at the right end, it is black.

Is there a way to define opacity in fade, such that the background image becomes visible?

M.W.E

\documentclass{beamer}
  \usepackage{tikz}
  \usepackage{graphicx}
  \usetikzlibrary{shapes.arrows, fadings}

  \setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth]{picture.jpg}}

  \begin{document}
    \begin{frame}
      \tikz{\fill[left color=red,right color=transparent] (0,0) rectangle (\linewidth,1.5em);}
    \end{frame}
  \end{document}

(Use any random picture for the background)

15

You need to set up a fading via \tikzfading and then use the fade path option to the fill command:

Sample output

\documentclass{beamer}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{shapes.arrows, fadings}

\setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth]{example-image-a.jpg}}

\tikzfading[name=fade right,
  left color=transparent!0, right color=transparent!100]

\begin{document}
\begin{frame}
  \tikz{\fill[red,path fading=fade right] (0,0) rectangle (\linewidth,1.5em);}
\end{frame}
\end{document}

See the section "Creating Fadings" (currently 23.4.1) of the pgfmanual.

  • In the latest version this has moved to 23.4.1 (page 341) – lanoxx Nov 7 '16 at 13:55

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.