[Tex/LaTex] Need to left align referenced image in mdframed Info box

boxesgraphicshorizontal alignmentmdframed

I have been successful at creating a set of Warning, Note, and Info boxes using mdframed package, and they look very good. However, I need to left align an inserted image rather than have it on its own line above the text, but below the frame title.

In fact, this question (and excellent answers!) got me where I am now: Rounded box with image and text. However, I need to modify the resultant box as described in my first paragraph (image left aligned and text to the right, but with the frametitle above the image). Here is what I have so far (I hope it is MWE, as I am not sure how to reference an external image in this example):

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{lipsum}% Used for dummy text.

\definecolor{warning}{RGB}{255,231,231}

% Definition for Warning Boxes                     
\mdfdefinestyle{warn}{roundcorner=10pt,
  skipabove=10pt
  skipbelow=10pt
  leftmargin=20pt,
  rightmargin=20pt,
  backgroundcolor=warning,
  innertopmargin=10pt,
  innerbottommargin=10pt,
  innerleftmargin=10pt,
  middlelinewidth=0pt,
  everyline=true,f
  linecolor=warnline,
  font=\normalfont\normalsize,
  shadow=true,
  frametitlefont=\normalfont\normalsize\bfseries,
  frametitleaboveskip=1em,
}                      

\begin{document}

\begin{mdframed}[style=warn, frametitle=Warning]
\includegraphics[scale=0.50]{<path>/<icon>} \\ Important warning not to be missed.
\end{mdframed}

\end{document}

It is important also that I can insert this Warning note by a simple line such as

\begin{warning}
This is the warning text.
\end{warning}

Thanks in advance for your assistance.

Best Answer

You can achieve what you want simply modifying the settings you were using and taking advantage of singleextra, firstextra to place the title and the image.

Notice that you had the default framemethod, so some of your settings were silently ignored; to prevent this, I changed to framemethod=tikz (I also defined a warnline color that was missing on your original code).

Instead of defining a style, as in your code, I defined an environment using \newmdenv; this allows you to simply use your desired syntax:

\begin{warn}
text
\end{warn}

The code (adjust the lengths according to your particular needs):

\documentclass[a4paper,11pt]{article}
\usepackage[demo]{graphicx}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}% Used for dummy text.
\usetikzlibrary{shadows}

\definecolor{warning}{RGB}{255,231,231}
\definecolor{warnline}{RGB}{155,231,231}

% Definition for Warning Boxes                     
\newmdenv[
  roundcorner=10pt,
  skipabove=10pt
  skipbelow=10pt
  leftmargin=20pt,
  rightmargin=20pt,
  backgroundcolor=warning,
  innertopmargin=30pt,
  innerbottommargin=10pt,
  innerleftmargin=70pt,
  middlelinewidth=0pt,
  everyline=true,
  linecolor=warnline,
  font=\normalfont\normalsize,
  shadow=true,
  frametitlefont=\normalfont\normalsize\bfseries,
  frametitleaboveskip=1em,
  singleextra={
    \node[inner sep=0pt,anchor=north west,xshift=10pt,yshift=-30pt] at (P-|O) {\includegraphics[width=1.8cm,height=1.8cm]{<path>/<icon>}};
    \node[inner sep=0pt,anchor=north west,yshift=-.8\baselineskip,font=\bfseries,xshift=10pt] at (P-|O) {Warning};    
  },
  firstextra={
    \node[inner sep=0pt,anchor=north west,xshift=10pt,yshift=-30pt] at (P-|O) {\includegraphics[width=1.8cm,height=1.8cm]{<path>/<icon>}};
    \node[inner sep=0pt,anchor=north west,yshift=-.8\baselineskip,font=\bfseries,xshift=10pt] at (P-|O) {Warning};    
  }
]{warn}                     

\begin{document}

\begin{warn}
\lipsum[4]
\end{warn}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.