20

Is there a way to emulate beamer blocks, e.g., alert/example, in ordinary pdflatex in article documents? Is there a pure tikz way of doing this?

2 Answers2

22

With version 2.00 of tcolorbox and its skin library it's possible to include beamer blocks in non-beamer documents. And now this blocks can break between columns and pages.

Here you have an example:

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[twocolumn,a4paper]{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins,breakable}
\usetikzlibrary{shadings,shadows}

\title{Beamer blocks in \texttt{article.cls} with \texttt{tcolorbox (v 2.00)}}
\author{xxxxxx}

\newenvironment{myexampleblock}[1]{%
    \tcolorbox[beamer,%
    noparskip,breakable,
    colback=LightGreen,colframe=DarkGreen,%
    colbacklower=LimeGreen!75!LightGreen,%
    title=#1]}%
    {\endtcolorbox}

\newenvironment{myalertblock}[1]{%
    \tcolorbox[beamer,%
    noparskip,breakable,
    colback=LightCoral,colframe=DarkRed,%
    colbacklower=Tomato!75!LightCoral,%
    title=#1]}%
    {\endtcolorbox}

\newenvironment{myblock}[1]{%
    \tcolorbox[beamer,%
    noparskip,breakable,
    colback=LightBlue,colframe=DarkBlue,%
    colbacklower=DarkBlue!75!LightBlue,%
    title=#1]}%
    {\endtcolorbox}

\begin{document}
\maketitle

\section{Section}

\lipsum[2]

\begin{myblock}{Example of \texttt{myblock}}
\lipsum[2-3]
\end{myblock}

\begin{myexampleblock}{Example of \texttt{myexampleblock}}
\lipsum[2]
\end{myexampleblock}

\begin{myalertblock}{Example of \texttt{myalertblock}}
\lipsum[1]
\end{myalertblock}

\end{document}

with its result

enter image description here

Ignasi
  • 136,588
  • 1
    Thanks for this! One minor but helpful modification which allows mathematics to appear in the title is to slightly modify the newenvironment command, replacing "title=#1" with "title={#1}". – Nathan Jul 27 '18 at 02:51
4

It is relatively easy to reproduce similar boxes using TikZ in a non-beamer document. For example, see here. Do you really need it to look exactly the same as in beamer? If so, you can just look at how it is implemented within beamer; I think it is defined either in beamerbaselocalstructure.sty or beamerinnerthemeinmargin.sty.

ESultanik
  • 4,410