15

I'm writing a programming book for novices and I'm making some text boxes to focus attention on them, like "Tips", "Warning", "Focus on" and so on. For now I'm using tcolorbox and I'm very happy with it, but I would like to add some small icons on the right (or left) side of the title bar. Another option could be to remove the title bar and add a side bar with the icon. In the manual of tcolorbox I have found several examples, but none of them show how to load images and add on the title bar. Any help would be wery appreciated.

[EDIT]

Here is a minimal example of my code:

\documentclass[10pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage[breakable]{tcolorbox}

% ----------------------------------------------------------------
\begin{document}

\begin{tcolorbox}[breakable,arc=0mm,colback=gray!5,colframe=gray,title=Warning!]%
\lipsum[1]
\end{tcolorbox}

\end{document}
% ----------------------------------------------------------------

The code rendered: enter image description here I would like something like: enter image description here or even: enter image description here

Another option could be

\documentclass[10pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage[breakable]{tcolorbox}

% ----------------------------------------------------------------
\begin{document}

\begin{tcolorbox}[breakable,arc=0mm,colback=gray!5,colframe=gray,leftrule=12mm]%
\lipsum[1]
\end{tcolorbox}

\end{document}
% ----------------------------------------------------------------

Rendering: enter image description here And the mokup: enter image description here

That's all :)

2
  • An image can be loaded by \includegraphics. You can use this command as any other character. Commented Jul 2, 2013 at 15:30
  • 1
    Please remove the edit and ask a new question. It's very hard to change an answer after every editing. Commented Jul 5, 2013 at 15:31

1 Answer 1

14

The package tcolorbox provides the option overlay and some other friends. A simple solution for your left part can be:

\documentclass{article}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}

\newtcolorbox{lattention}{breakable,enhanced,arc=0mm,colback=gray!5,colframe=gray,leftrule=12mm,%
overlay={\node[anchor=north west,outer sep=2pt] at (frame.north west) {\includegraphics[width=8mm]{attention}}; }}

\usepackage{lipsum}
\begin{document}
\begin{lattention}
\lipsum[2]
\end{lattention}

\begin{lattention}
\lipsum
\end{lattention}
\end{document}

Of course you need the picture attention. After this the result will be:

enter image description here

The adjustment is yours ;-)

1
  • In the last box, how can I center the image with the right content??? thanks for your help.. Commented Aug 14, 2016 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .