How do I change the block template for specific theorem environments (LaTeX beamer)

19,313

As seen in beamerbasetheorems.sty:

\documentclass[notheorems]{beamer}

\theoremstyle{plain}
\newtheorem{theorem}{\translate{Theorem}}
\newtheorem{example}[theorem]{\translate{Example}}

% or

\theoremstyle{definition}
\newtheorem{theorem}{\translate{Theorem}}
\newtheorem{example}[theorem]{\translate{Example}}

% or

\theoremstyle{example}
\newtheorem{theorem}{\translate{Theorem}}
\newtheorem{example}[theorem]{\translate{Example}}

Whatever style you like. You can also change the appearance of the [alert|example]block:

\setbeamercolor{block body}{fg=blue,bg=white}
\setbeamercolor{block body alerted}{fg=blue,bg=white}
\setbeamercolor{block body example}{fg=blue,bg=white}

(Not tried it, just looked into the beamer sources)

EDIT: Still not sure want you want to do, but you can define your own theorem styles:

\makeatletter
\def\th@something{%
  \normalfont % body font
  \def\inserttheoremblockenv{alertblock}  
}
\theoremstyle{something}
\newtheorem{warn}[theorem]{WARNING}
\makeatother

\begin{warn}[Attention please]
This is dangerous
\end{warn}

(This works, I tested it)

You have 3 predefined blocks which you can customize using \defbeamertemplate. Look into the sources and the documentation on how to do this. If you need more block environments, see basebeamerlocalstructure.sty:

  \newenvironment<>{alertblock}[1]{%
    \begin{actionenv}#2%
      \def\insertblocktitle{#1}%
      \par%
      \mode<presentation>{%\usebeamerfont{block}%
        \setbeamercolor{local structure}{parent=alerted text}}%
      \usebeamertemplate{block alerted begin}}
    {\par%
      \usebeamertemplate{block alerted end}%
    \end{actionenv}}

Hope that helps

Share:
19,313
Matthew Leingang
Author by

Matthew Leingang

Mathematics professor by day, hacker by night. Stackexchange is my procrastination mechanism. I teach calculus and try to implement teaching and new media technologies. I use a lot of LaTeX and the occasional scripting language. I use he/him/his pronouns.

Updated on July 19, 2022

Comments

  • Matthew Leingang
    Matthew Leingang almost 2 years

    The amsthm theorem environments (theorem,example,proof,solution,...) make blocks on beamer slides. The default is that example environments use a different template (block example) than theorem or solution or proof (block).

    How do I make solution use a different template like "block solution" that I can define?

    Edit: Thanks to those who answered. I haven't implemented a workaround yet but it seems like there are two ideas:

    • Redefine the \th@foo command for a theorem-like environment named foo. The new command should redefine \inserttheoremblockenv to be the desired block environment. See beamerbasetheorems.sty (around line 63) for how this is done specifically for example.

    • Redefine the theorem begin and theorem end template to look up the correct theorem block environment based on the global variable \inserttheoremname (see beamerinnerthemedefault.sty). The lookup table could be kept in a pgfkeys registry. This approach would be a bit higher-level and wouldn't involve any commands with @ in them; however, YAGNI comes to mind.

  • Matthew Leingang
    Matthew Leingang about 14 years
    What I really want to do is create a new alternative to theorem/example/alert blocks. beamerbasetheorems.sty overrides one of amsthm's internals so as to use a "theorem begin" template when a theorem-like enviroment is begin. That template starts a block environment named '\insertblockenv'. This macro is defined in beamerbasetheorems.sty to be "block", and only in an override of an internal '\th@example' is the '\insertblockenv' macro redefined to "exampleblock". So those are your choices: exampleblock if the theoremstyle is example, block o/w. Maybe the template can be adapted?
  • Meinersbur
    Meinersbur about 14 years
    Do you want to change an existing block environment or define a new block environment?
  • Matthew Leingang
    Matthew Leingang about 14 years
    I want to change an existing block environment. I don't want "theorem" and "solution" (for instance) to be in the same beamercolorbox. I won't have a chance to get back to this for another day or two, but I think something can be accomplished using PGF's key registry within the theorem begin template.
  • Matthew Leingang
    Matthew Leingang about 14 years
    Or, maybe just hack \th@solution to change \insertblockenv like beamerbasetheorems.sty does with \th@example.
  • Meinersbur
    Meinersbur about 14 years
    Is what you are trying to accomplish in my edit? Do you need more block environments or help to create new ones?