17

Scenario

I want to create a warning box (or pitfall box) that satisfies the following creteria:

  1. It can be broken across pages.
  2. It can contain images, displayed equations, begin{minipage}, \begin{multicols} and \lstinputlisting.
  3. It occupies the whole width of the page.
  4. It is enclosed by a red frame.
  5. It looks like the following figure but the background color should be yellowish.

Bird's View

alt text

Zoomed-in View

alt text

Display Name
  • 46,933

2 Answers2

18
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{pifont,mdframed}

\newenvironment{warning}
  {\par\begin{mdframed}[linewidth=2pt,linecolor=red]%
    \begin{list}{}{\leftmargin=1cm
                   \labelwidth=\leftmargin}\item[\Large\ding{43}]}
  {\end{list}\end{mdframed}\par}

\begin{document}
\blindtext
\begin{warning}
\blindtext
\end{warning}
\blindtext[2]
\begin{warning}
\blindtext[2]
\end{warning}

\end{document}
2

Shortcoming

  1. The figure has not been vertically centered.
  2. The lack of red frame.

Screenshot

alt text

Minimal Code

\documentclass[dvipsnames,cmyk]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{lipsum,graphicx,xcolor,framed}

\renewenvironment{leftbar}[1][\hsize]%
{%
        \def\FrameCommand%
        {%
             \includegraphics[width=1cm]{pitfall}%           
             \fboxsep=\FrameSep\colorbox{cyan!5}%
        }%
        \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}%
{\endMakeFramed}


\def\dummy{bla bla bla bla bla bla bla bla bla bla bla bla bla bla.}
\begin{document}
\lipsum[1]

\begin{leftbar}[0.5\linewidth]
\noindent\dummy
\[
\int_a^b f(x)\,\textrm{d}x=F(b)-F(a)
\]
\dummy
\end{leftbar}

\lipsum[1]
\end{document}
Display Name
  • 46,933