15

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?

  • 1
    What exactly do you want to achieve? Colored text? The box around theorem environments? – Caramdir Aug 29 '10 at 19:23
  • Rounded corners, shadows, two colors (title/body). I have seen some tikz examples, but they are not 100% satisfactory. – E.Verbitskiy Aug 29 '10 at 19:36
16

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

  • 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 2: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.

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.