Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable transparent background of beamercolorbox #884

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrjabs
Copy link

@chrjabs chrjabs commented Feb 8, 2024

I am working on a beamer theme right now and found myself wanting colorboxes with truly transparent backgrounds. I found a stackexchange post addressing this topic and then noticed that implementing this as a proper parameter bgopacity for beamercolorbox and beamerboxesrounded does not seem too hard.

The result is cleanest for non-rounded boxes, as they are drawn as one shape.
For rounded boxes, especially with a heading, the box can sometimes get tiny gaps, as the shapes can't overlap with transparent background colours.
I made sure that the shapes still overlap when no transparency is used, so that the gaps don't appear in this case.

Here is an example of what I get with my code.

An example of  colorboxes with transparent background

The LaTeX code to generate the example above
\documentclass[xcolor=usenames,dvipsnames]{beamer}

\colorlet{color1}{PineGreen}

 \mode<presentation>
{
\usetheme{default}
\usecolortheme{lily}
\usefonttheme{professionalfonts}
\setbeamercolor{alert}{fg=red!80!black}
\setbeamercolor{text1}{fg=color1!80!black}
\setbeamercolor{text2}{fg=black}
\setbeamercolor{structure}{fg=color1!80!black}
\setbeamercolor{frametitle}{fg=red!80!black}
\setbeamercolor{box1}{fg=black,bg=Dandelion}
\setbeamercolor{box2}{fg=black,bg=SeaGreen}
\setbeamercolor{box3upper}{fg=black,bg=blue}
\setbeamercolor{box3lower}{fg=black,bg=orange}

\setbeamerfont{frametitle}{series=\bfseries}
\setbeamertemplate{frametitle}
{
  \begin{flushright}
    \insertframetitle\par
  \end{flushright}
}
\usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{lion.png}}
\setbeamercovered{transparent}
\setbeamerfont{title}{size=\Large,series=\bfseries,shape=\itshape,family=  \rmfamily}
\setbeamercolor{title}{fg=red!80!black}
}

\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}

\begin{document}

\begin{frame}
\frametitle{slide title}
\begin{columns}
\column{0.5\textwidth}
  \begin{beamercolorbox}[shadow=true,rounded=true,bgopacity=.35]{box1}
    {\usebeamercolor[fg]{text2} \bf T1}
    \begin{itemize}
    \item element
    \item element
    \item element
    \item element
    \item element
    \end{itemize}
  \end{beamercolorbox}
\column{0.5\textwidth}
  \begin{beamercolorbox}[shadow=true,rounded=false,bgopacity=.35]{box2}
    {\usebeamercolor[fg]{text2} \bf T2}
    \begin{itemize}
    \item element
    \item element
    \item element
    \item element
    \end{itemize}
  \end{beamercolorbox}
\end{columns}
\begin{beamerboxesrounded}[bgopacity=.35,upper=box3upper,lower=box3lower]{Testtitle}
  \begin{itemize}
    \item element
    \item element
  \end{itemize}
\end{beamerboxesrounded}
\end{frame}

\end{document}

The implementation is based on this stackexchange post and I made the following additional modifications:

  • implement transparent background for rounded=false: the stackexchange post only made modifications to beamerboxesrounded, not to non-rounded boxes that are drawn directly in beamercolorbox
  • make sure boxes are not affected with bgopacity=1: in order to make sure I'm not messing anything up, pretty much all changes are guarded by if bgtransparency != 1 (looking through the theme examples in the userguide, they all still look fine to me)
  • more exact clipping of shadows when transparent background is used

@samcarter
Copy link
Collaborator

samcarter commented Feb 8, 2024

Thanks for your pull request! I had a quick look at the code, but did not have time yet to test. Just some things I'm wondering about:

  • shouldn't the option be documented for both kinds of colourboxes?

  • on the left hand side, the shadow is visible behind the semi-transparent box:

Screenshot 2024-02-08 at 13 59 08

@chrjabs
Copy link
Author

chrjabs commented Feb 8, 2024

Good points, I entirely missed that beamerboxesrounded is documented. I added the missing documentation and fixed the shadow clipping.

@samcarter
Copy link
Collaborator

One point to think about: with the default value of 1, the opacity will no longer adopt to the surrounding opacity. This means existing code like https://tex.stackexchange.com/a/656921/36296 or https://tex.stackexchange.com/a/331416/36296 will no longer give the desired result.

@chrjabs
Copy link
Author

chrjabs commented Feb 20, 2024

Right. I guess one could leave \bmb@bgopacity undefined by default and only call \pgfsetfillopacity if it is defined. Or did you have another idea for how to deal with this?

@samcarter
Copy link
Collaborator

samcarter commented Feb 20, 2024

Right. I guess one could leave \bmb@bgopacity undefined by default and only call \pgfsetfillopacity if it is defined. Or did you have another idea for how to deal with this?

Yes, this could work.

Or maybe avoid all potential backwards compatibility problems by creating a new transparent box?

implementation based on https://tex.stackexchange.com/questions/75839/transparency-of-beamercolorbox-and-opaqueness-of-its-text

additional things that needed fixing:
- implement transparent background for `rounded=false`
- by default, don't change anything by not defining the `bgopacity`
  macros
- more exact clipping of shadows when `bgopacity` is set
@chrjabs
Copy link
Author

chrjabs commented Feb 27, 2024

Got around to implementing this with not defining \bmb@bgopacity by default. The example from https://tex.stackexchange.com/a/656921/36296 seems to build without an issue.
I am not entirely sure what would happen now if you do something like this:

\begin{beamercolorbox}[bgopacity=.5]
\begin{beamercolorbox}
\end{beamercolorbox}
\end{beamercolorbox}

I suppose the inner box would still be drawn with 0.5 opacity, but I think this is a pretty niche case and can be easily fixed by setting bgopacity=1 on the inner box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants