5

Many times we see in books, some significant points, some tips and tricks are put in an attractive box with an image in it (usually the text will be in italics). I would like to achieve the same effect. I have referred this link : Adding an Image inside tcolorbox. And this is what I have achieved :

\documentclass[12pt]{article}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[
%      breakable,
      left=0pt,
      right=0pt,
      top=8pt,
      bottom=8pt,
      colback=white,
      colframe=red,
      width=\textwidth,
      enlarge left by=0mm,
      boxsep=5pt,
      arc=4pt,
      outer arc=4pt,
    ]
    \Large
  \smash{\raisebox{-11pt}{\includegraphics[width=1cm,height=1cm]{colorbox}}}\hfill
\end{tcolorbox}
\end{document} 

Output:

enter image description here
Now, my question is, How to align that image and add a text not at the center but as a paragraph.

What I want to achieve is :

enter image description here

  • As an alternative to tcolorbox, bclogo was designed to make this kind of boxes: framed and colorfull boxes with a little logo on them. – Ignasi May 29 '14 at 15:55
  • Can you show me a sample MWE @Ignasi – subham soni May 29 '14 at 15:58
  • Yes, but because is not what you want I've added here – Ignasi May 29 '14 at 17:57
8

Adjust the settings according to your needs:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usetikzlibrary{calc}

\newtcolorbox{mybox}{
  enhanced,
  left=0pt,
  right=0pt,
  top=8pt,
  bottom=8pt,
  colback=white,
  colframe=red,
  width=\textwidth,
  enlarge left by=0mm,
  boxsep=5pt,
  fontupper=\itshape\small,
  arc=4pt,
  outer arc=4pt,
  leftupper=1.5cm,
  overlay={
    \node[anchor=west] 
      at ([xshift=10pt] $ (frame.north west)!0.5!(frame.south west) $ )
       {\includegraphics[width=1cm,height=1cm]{example-image-a}};}
}
\begin{document}
\begin{mybox}
\lipsum[4]
\end{mybox}
\end{document}

enter image description here

Or with a different vertical alignment for the image:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{mybox}{
  enhanced,
  left=0pt,
  right=0pt,
  top=8pt,
  bottom=8pt,
  colback=white,
  colframe=red,
  width=\textwidth,
  enlarge left by=0mm,
  boxsep=5pt,
  fontupper=\itshape\small,
  arc=4pt,
  outer arc=4pt,
  leftupper=1.5cm,
  overlay={
    \node[anchor=north west] 
      at ([xshift=10pt,yshift=-.65\baselineskip]frame.north west)
       {\includegraphics[width=1cm,height=1cm]{example-image-a}};}
}
\begin{document}
\begin{mybox}
\lipsum[4]
\end{mybox}
\end{document}

enter image description here

  • Nice answer! Note to self: option enhanced very much needed to support \includegraphics inside overlay= option, in my experience. – PatrickT Nov 29 '18 at 18:40
  • If your box has a title, and you want to centre align the image to the content of the box, you will have to use interior.north west)!0.5!(interior.south west) instead. I know this isn't exactly what the OP asked but thought it would be useful :) – Michael Harper Dec 2 '18 at 13:05

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.