20

I'd like to automatically change the color of the text according to the background color.

I've used tikz to create the background (the shape is only an example) but any other way to do it is welcome.

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Madrid}
\usebackgroundtemplate{%
    \begin{tikzpicture}
        \coordinate (A) at (0,0);
        \coordinate (B) at (0,\paperheight);
        \coordinate (C) at (\paperwidth,0);
        \fill[blue] (A) -- (C) -- (B) -- cycle;
    \end{tikzpicture}
}
\begin{document}
\begin{frame}
    \frametitle{Example}
    Could this text be automatically white on blue and blue on white?
\end{frame}
\end{document}

enter image description here

4
  • 1
    Intuitively you'll have to do this manually using clipping.
    – Werner
    Commented Mar 3, 2017 at 22:02
  • I don't know much about clipping in tikz.
    – Werner
    Commented Mar 3, 2017 at 22:25
  • +1 nice question! I am sure that PowerPoint can't do this hehe lol
    – manooooh
    Commented Sep 7, 2018 at 6:01
  • 1
    @manooooh Indeed, it can't. I asked just for that reason :):):)
    – CarLaTeX
    Commented Sep 7, 2018 at 6:02

1 Answer 1

23

The idea is simple: use some nontrivial blending mode.

You might want to

  • tune the colors, so that "blue" minus "yellow" is "white"
  • modify the background, so that the lower right corner looks right.

I test the document with Preview and Adobe Reader on Mac.


\documentclass{beamer}
\usepackage{tikz}
\usetheme{Madrid}
\usebackgroundtemplate{
    \begin{tikzpicture}
        \coordinate (A) at (0,0);
        \coordinate (B) at (0,\paperheight);
        \coordinate (C) at (\paperwidth,0);;
        \coordinate (D) at (\paperwidth,\paperheight);
        \fill[blue] (A) -- (C) -- (B) -- cycle;
        \fill[white](D) -- (C) -- (B) -- cycle;
    \end{tikzpicture}
}
\begin{document}

\begin{frame}
    \frametitle{Example}
    \pgfsetblendmode{difference}
    \color{yellow}Could this text be automatically white on blue and blue on white?
\end{frame}

\end{document}

Edit:

As @Werner suggested, if you do not know how to fix the footline, add this line:

\addtobeamertemplate{footline}{\pgfsetblendmode{normal}}{}

Change footline to anything else if you find them unexpected.

On the other hand, if you think it is awesome,

\addtobeamertemplate{navigation symbols}{\pgfsetblendmode{difference}}{}

2
  • I knew that some tikz expert would have provided a gorgeous solution, thank you!
    – CarLaTeX
    Commented Mar 4, 2017 at 7:11
  • 1
    The better fix for the navigation symbols is \setbeamertemplate{navigation symbols}{}. I've listened to (and given) lots of beamer talks in my life, but have never seen anyone use these links (except inadvertently).
    – gernot
    Commented Mar 4, 2017 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .