[Tex/LaTex] How to make these boxes

automationboxesdiagramsformattinggraphics

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.

enter image description here

Best Answer

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}

enter image description here

Using tcolorbox; adjust the settings according to your needs:

enter image description here

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}

enter image description here