3

With the following command I can change block title background color:

\setbeamercolor{block title}{bg=blue!20,fg=black}

How can I instead have a background image for the block title? (I'm thinking of tiling an image to create a nicer look)

3
  • Welcome to TeX.SX! – osjerick Sep 12 '14 at 19:11
  • There is no direct option as for setting the background color. You can (easier solution) use the tcolorbox package to create some some new blocks with a title background or (more difficult solution) you can hack the block template to insert an image, but it will not look good in all the standard beamer themes. What theme are you using? – Old Nick Sep 12 '14 at 22:18
  • Could you give an example of the easier method? I'm using the Singapore theme. – fjjsla Sep 12 '14 at 22:26
1

Full code

\documentclass{beamer}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{tikz}
\usetheme{Singapore}


\newenvironment<>{myblock}[1]{%
  \begin{actionenv}#2%
      \def\insertblocktitle{
        \vskip-.15cm\hspace*{-.38cm}
          \tikz\node[text width=.98\textwidth+.45cm,inner sep=.18cm,font=\bfseries,text=black,path picture={
            \node at (path picture bounding box){\includegraphics[width=\textwidth]{hearts}};
          }]{#1};
          \vskip-.15cm
      }
      \mode<presentation>{%
       \setbeamercolor{block title}{fg=black,bg=gray!20}
       \setbeamercolor{block body}{fg=black,bg=white}
       \setbeamercolor{itemize item}{fg=orange!20!black}
       \setbeamertemplate{itemize item}[triangle]
     }%
      \usebeamertemplate{block begin}}
    {\par\usebeamertemplate{block end}\end{actionenv}}

\newtcolorbox{mytblock}[1]{
    enhanced,
    title=#1,
    title style tile={width=\textwidth}{hearts},
    arc=0pt,
    boxrule=0pt,
    colback=white,
    fonttitle=\bfseries,
    coltitle=black,
    lefttitle=-1pt,
    toptitle=3pt,
    bottomtitle=3pt,
    leftupper=1pt,
}

\begin{document}
\begin{frame}
    \begin{myblock}{This is a title}
        test
    \end{myblock}

    \begin{mytblock}{This is a title}
        test
    \end{mytblock}
\end{frame}
\end{document}

enter image description here

Above you have two approaches:

  1. Hack the block template (myblock)
  2. Use the tcolorbox packge to create a block which looks like a beamer block (mytblock)

The tcolorbox package already has a built-in title style tile that will let you insert any background picture and tile it for you. Note that in the MWE I used a big picture (like 600x480) which was already tiled by itself and so I had:

title style tile={width=\textwidth}{hearts}

If you have a non tiled picture, the first variable would specify the width of a single picture, so you'll have something like

title style tile={width=1cm}{<non-tiled-picture>}

Since you're using the Singapore theme a similar result can be achieved by hacking the beamer block template. As you can see the code is more complicated (a bit hackish) and in this case you need to use an already-tiled picture like mine (unless you want to complicate things even more).

you can find the hearts picture here.

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.