0

I am trying to create a box or a coloured section with a border and a logo, something like this warning section: enter image description here

Or like this, not so nice, code link: enter image description here

Which is repeated during the book for highlighting when some reference to a code is used.

What's the name of this typographical element?

How can create my own?

I was trying to use \newcommand or \newenvironment but I would appreciate some recommendations before starting some trials.

G M
  • 2,225

1 Answers1

3

As Cragfelt suggested, tcolorbox could be an alternative as it's shown in following example. bclogo could be another option.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{fontawesome}

\newtcolorbox{myalert}[1][]{
    enhanced,
    notitle,
    sharp corners,
    boxrule=1pt,
    borderline west={2mm}{0mm}{red},
    width=.8\linewidth,
    center,
    before upper={\textcolor{red}{\large\faBomb\ }},
    #1
    }

\begin{document}
\lipsum[1]
\begin{myalert}
This is some important advertisement!
\end{myalert}
\lipsum[2]
\end{document}

enter image description here

Update: using own logos.

Your own logo can be inserted with \includegraphics command. In following code you'll find three possible implementations with tcolorbox. The first one includes the logo as a character, the second one divides the box between logo and text and the third one uses wrapfig box to include a wrapped logo.

Used logo comes from openclipart

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{wrapfig}
%\usepackage{fontawesome}

\newtcolorbox{firstalert}[1][]{
    enhanced,
    notitle,
    sharp corners,
    boxrule=1pt,
    borderline west={2mm}{0mm}{red},
    width=.8\linewidth,
    center,
    before upper={\includegraphics[height=8mm]{Atencio}\ },
    #1
    }

\newtcolorbox{secondalert}[1][]{
    enhanced,
    sidebyside,
    lefthand width=2cm,
    bicolor,
    colback=red!20,
    colbacklower=yellow!10,
    notitle,
    sharp corners,
    boxrule=1pt,
    borderline west={2mm}{0mm}{red},
    width=.8\linewidth,
    center,
    #1
    }

\newtcolorbox{thirdalert}[1][]{
    enhanced,
    notitle,
    sharp corners,
    boxrule=1pt,
    borderline west={2mm}{0mm}{red},
    width=.8\linewidth,
    center,
    before upper={\begin{wrapfigure}{l}{.2\linewidth}\centering\includegraphics[width=.9\linewidth]{Atencio}\end{wrapfigure}},
    #1
    }


\begin{document}
\begin{firstalert}
This is some important advertisement! \lipsum[2]
\end{firstalert}
%\lipsum[2]
\begin{secondalert}[width=.9\linewidth]
\includegraphics[width=\textwidth]{Atencio}
\tcblower
This is some important advertisement! \lipsum[2]
\end{secondalert}
\begin{thirdalert}[width=.9\linewidth]
This is some important advertisement! \lipsum[2]
\end{thirdalert}

\end{document}

enter image description here

Ignasi
  • 136,588