# How to make these boxes?

I don't know how exactly to call what I want to implement. It's like a box surrounded with a line and, depending on the context, I want to place a graphic on the right corner e.g. a light bulb or a question mark.

I want to place these boxes in more than one place, so if there's a link explaining how to automate these things - a macro I guess - that would be appreciated too.

# Update

After new requirement in comments, now theres just one environment coolbox with a mandatory argument (the file image to be used) and two optional ones:

\begin{coolbox}[<options for the box>]{<image-file>}[<options for the image>]
(contents)
\end{coolbox}


The code:

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

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
common/.style={
before=\vskip2\baselineskip\noindent,
after=\vskip2\baselineskip,
enhanced,
frame code={},
fontupper=\LARGE,
fontlower=\LARGE,
segmentation empty,
middle=0.7cm,
top=0.5cm
}
}

\DeclareTColorBox{coolbox}{O{}mO{}}{
common,
interior code={
\filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt,#1] (interior.north west) rectangle (interior.south east);
\node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[#3]{#2}};
},
}

\begin{document}

\begin{coolbox}{lightbulb}[height=2cm]
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\begin{coolbox}{questionmark}[width=1cm,angle=-20]
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\begin{coolbox}[fill=red!20,draw=red]{exclamationmark}[width=1.5cm,angle=-20]
Did you know that adding some more text
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\end{document}


Using tcolorbox; adjust the settings according to your needs:

The code:

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

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
common/.style={
before=\vskip2\baselineskip\noindent,
after=\vskip2\baselineskip,
enhanced,
colback=boxbg,
frame code={},
fontupper=\LARGE,
}
}

\newtcolorbox{ideabox}{
common,
interior code={
\filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
\node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=2.5cm]{lightbulb}};
}
}
\newtcolorbox{questionbox}{
common,
interior code={
\filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
\node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=1.5cm,angle=-30]{questionmark}};
}
}

\begin{document}

\begin{ideabox}
Did you know:\par\vskip1cm

Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{ideabox}

\begin{questionbox}
Did you know:\par\vskip1cm

Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{questionbox}

\end{document}


If all the boxes are going to have this structure (i.e., an upper and a lower part), then (as cmhughes suggests in his comment) one can use \tcblower and middle to avoid manually producing the vertical separation:

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

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
common/.style={
before=\vskip2\baselineskip\noindent,
after=\vskip2\baselineskip,
enhanced,
colback=boxbg,
frame code={},
fontupper=\LARGE,
fontlower=\LARGE,
segmentation empty,
middle=0.7cm
}
}

\newtcolorbox{ideabox}{
common,
interior code={
\filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
\node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=2.5cm]{lightbulb}};
}
}
\newtcolorbox{questionbox}{
common,
interior code={
\filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
\node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=1.5cm,angle=-30]{questionmark}};
}
}

\begin{document}

\begin{ideabox}
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{ideabox}

\begin{questionbox}
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{questionbox}

\end{document}


• +1 :) instead of the \par\vskip1cm could you do something with tcbupper? just curious :) Sep 28 '15 at 19:43
• @cmhughes Thanks. Sure. But since I wasn't sure about the real use of the box (it's not clear if in every use it's going to be this kind of separation) I decided not to use tcbupper. Perhaps I'll add a variation with tcbupper later. Sep 28 '15 at 19:51
• @cmhughes Answer updated using \tcblower. Sep 30 '15 at 2:59
• @ChristianHupfer After request from the OP, this has changed in the updated answer. Oct 12 '15 at 20:14
• @user2692669 Yes. You can change the top value to suit your needs. Or move the image a little upwards changing the yshift=5pt shift I used in the node for the image. Oct 13 '15 at 0:02

\documentclass[border=2pt]{standalone}
\usepackage{tikz,xcolor}
\usetikzlibrary{calc}
\definecolor{skyblue}{HTML}{B9E1FD}

\begin{document}

\begin{tikzpicture}[line width=.7pt, inner sep=7pt]
\node [draw,rounded corners,dashed,fill=skyblue,text width=.6\textwidth] (B){%
\bfseries Did you know? \par \bigskip
Once upon a time there was a latch that wanted to be a flip.flop};
\node [rotate=-30]at($(B.north)!.65!(B.north east)$) {\includegraphics[scale=.09]{bulb}};
\end{tikzpicture}

\end{document}


TikZ can also be used to produce such fancy boxes. The width can be adjusted as required (I used .65\textwidth here). Also the color is your choice (I used {HTML}{B9E1FD} here).

\node at ($(B.north)!.72!(B.north east)$) {\includegraphics{quest}};