1

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.

  • 1
    Clarification: I know how to reference images, but not using stackexchange code samples. – GlenninBerlin May 28 '13 at 21:13
0

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.

  • Thank you @GonzaloMedina. Just what I needed. I had to adjust the size of the graphic (in scale), but I am not sure how to adjust the positioning of the image using: {inner sep=0pt,anchor=north west,xshift=10pt,yshift=-30pt}. I imagine the image is placed 10pt up the x axis and 30pt along the y axis from the bottom left corner of the box (sep=0)? – GlenninBerlin May 29 '13 at 15:12
  • @GlenninBerlin To adjust the positioning, use xshift=<length> (horizontal displacement: positiva values, to the right), yshift=<length> (vertical displacement; positive values going upwards); the origin for this displacements is the upper left corner of the big (pink) frame. Also, don't forget to accept the answer that you consider best solved your problem by clicking the checkmark to its left (in case of doubt, please see How do you accept an answer?. – Gonzalo Medina May 29 '13 at 15:45
  • @GlenninBerlin (Continuation) anchor=north west just fixes the selected corner as the origin; inner sep=0pt just builds a node without inner separation (the node size will exactly fit the contents). Probably you don't need to change these settings. – Gonzalo Medina May 29 '13 at 15:47
  • Thanks @GonzaloMedina (again!). Ah, ok - upper left corner of the frame. This was very helpful as I have to adjust spacing, size, and positioning of the graphic. BTW, both answers were really helpful and taught me more about Latex, but I was able to use your answer in my current problem. So, I'd click yours, but wish there was a "like" button also for the effort of the previous respondent. – GlenninBerlin May 29 '13 at 18:54
  • @GlenninBerlin yes, you can say "I liked this solution" by up-voting it. Unfortunately, you need some more reputation before being able to up-vote (don't ask me why; those are the rules). – Gonzalo Medina May 29 '13 at 23:40
0

I would use two minipages inside the mdframed environment. I also centered the title of the box with the frametitlealignment=\centering. All this is wrapped inside a new \warning command. The complete code:

\documentclass[a4paper,11pt]{article}
\usepackage[demo]{graphicx}% remove demo option, it is just to have a dummy black rectangle as figure
\usepackage{xcolor}
\usepackage{lipsum}% Used for dummy text.
\usepackage{mdframed}
\usepackage{calc}

\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,
  linecolor=warning,
  font=\normalfont\normalsize,
  shadow=true,
  frametitlefont=\normalfont\normalsize\bfseries,
  frametitleaboveskip=1em,
  frametitlealignment=\centering
}

\newcommand{\warning}[1]{%
  \begin{mdframed}[style=warn, frametitle=Warning]
  \begin{minipage}[c]{2cm}
    \includegraphics[width=2cm,height=2cm]{test}
  \end{minipage}%
  \hspace*{0.5cm}%
  \begin{minipage}[c]{\textwidth-2.5cm}
  #1\end{minipage}
  \end{mdframed}
}

\begin{document}
\warning{Important warning not to be missed. Text text text text text text 
  text text text text text text text text text text text text text.}
\end{document}

gives:

sample output

A final note: please make your MWE's compilable. The code in your question has some glitches.

  • Thank you @mafp! It was very useful to see how I can use a minipage in such a box. I may have to use this in another context, so very helpful! – GlenninBerlin May 29 '13 at 15:20

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.