# Rounded box with image and text

I'm trying to create a rounded box with both text and image. The desired result is as this:

Where the image is rounded at the left edges.

I have managed everything except the the image part using mdframed as follows:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{color}
\usepackage[margin=0pt,bottom=1em]{geometry}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}

\mdfdefinestyle{item}{roundcorner=10pt,
leftmargin=20pt,
rightmargin=20pt,
backgroundcolor=gray,
innertopmargin=.5em,
innerbottommargin=10pt,
innerleftmargin=200pt,
middlelinewidth=0pt,
font=\normalfont\large,
frametitlefont=\normalfont\Large\bfseries,
frametitleaboveskip=1em}

\begin{document}

\vfill % autospace boxes when there are more than one
\begin{mdframed}[style=item,frametitle=title]
Auto wrapped text aaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaa
\end{mdframed}

\end{document}


If the image scales to fit height of box and then crops at the text that would be good, but as long as aspect ratio is preserved I can adapt my images to work with most ways.

Any ideas how to proceed from here? Is there a better way than using mdframed?

-
Welcome to TeX.sx! –  Peter Jansson Mar 13 '13 at 15:43
The positioning of a picture in the left part can be done by the option singleextra. An inspiration of how it works can be found here: tex.stackexchange.com/questions/52023/… –  Marco Daniel Mar 13 '13 at 18:01

Without using extra boxes, you can simply use singleextra (for non-breaking frames) and TikZ \node and \draw commands, to draw the vertical rule and place the image at the desired position; a complete example (of course, adjust the used lengths according to your needs):

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0pt,bottom=1em]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc}
\usepackage{lipsum}% just to generate text for the example

\mdfdefinestyle{item}{roundcorner=10pt,
leftmargin=20pt,
rightmargin=20pt,
backgroundcolor=gray,
innertopmargin=.5em,
innerbottommargin=10pt,
innerleftmargin=200pt,
middlelinewidth=0pt,
font=\normalfont\large,
frametitlefont=\normalfont\Large\bfseries,
frametitleaboveskip=1em,
singleextra={
\draw[black,ultra thick]
([xshift=190pt]P-|O) -- ([xshift=190pt]O);
\path let \p1 = ( $(O)!0.5!(P)$ ) in
(\the\dimexpr0.5\mdflength{innerleftmargin}\relax,\y1) coordinate (Q);
\node at (Q) {\includegraphics[width=\the\dimexpr0.7\mdflength{innerleftmargin}\relax]{verde}};}
}

\begin{document}

\begin{mdframed}[style=item,frametitle=title]
\lipsum[4]
\end{mdframed}

\vspace*{1cm}

\begin{mdframed}[style=item,frametitle=title]
\lipsum[1-2]
\end{mdframed}

\end{document}


An image of the resulting document:

One then could also use firstextra, secondextra, etc. if frames must split, and if the image will have to go in one specific place.

-

In my opinion, it could be difficult to position your picture with your proposition.

I would suggest to proceed in a different way:

1/ Typeset your text in a saved box in order to compute the height of the text

\newsavebox{\tmpbox}
\savebox{\tmpbox}{\parbox{...width...}{...content...}}


2/ Assuming you know the maximal width of your picture, you will be able to include the picture with the right aspect ratio. I'm using a \parbox to center it toward the baseline. Notice that you need the calc package

\newlength\mymeasure
\settototalheight{\mymeasure}{\usebox{\tmpbox}}
\parbox{...maxwidth...}{%
\centering%
\includegraphics[width=...maxwidth...,height=\mymeasure,keepaspectratio]{...picture path...}%
}
\usebox{\tmpbox} % use the text box


3/ you can put the above lines in the mdframed to draw the frame

Exemple:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{calc}
\usepackage[framemethod=TikZ]{mdframed}

\mdfdefinestyle{item}{roundcorner=10pt,
leftmargin=20pt,
rightmargin=20pt,
backgroundcolor=gray,
innermargin=10pt,

\begin{document}

\begin{mdframed}[style=item]
\newsavebox{\tmpbox}
\savebox{\tmpbox}{\parbox{.5\columnwidth}{%
\textbf{\Large Title}

Auto wrapped text aaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaaaaa aaaa a aaa a aaaaa aaaa
}}

\newlength\mymeasure
\settototalheight{\mymeasure}{\usebox{\tmpbox}}
\parbox{.4\columnwidth}{%
\centering%
\includegraphics[width=.3\columnwidth,height=\mymeasure,keepaspectratio]{test}%
}
\usebox{\tmpbox}
\end{mdframed}

\end{document}


-

Thanks to both the answer from Lionel and Gonzalo together with image scaling from Scale included graphics to the higher ratio instead of the lower for given width, height and the \clip command for rounding the corners I managed to get what I wanted.

It first creates the text in a box like @LionelMANSUY did and then rescales and rounds the image and inserts it via singleextra as in @GonzaloMedina answer

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {./meta/} }
\usepackage[margin=0pt,bottom=1em]{geometry}
\usepackage{tikz}
\usepackage{calc}
\usepackage{lipsum}
\usetikzlibrary{calc}
\usepackage[framemethod=TikZ]{mdframed}

\newlength\ztextheight
\newlength\zimwidth\setlength{\zimwidth}{130pt}      % Image width
\newlength\zimmargin\setlength{\zimmargin}{20pt}     % Image<>Text margin
\newlength\ztextwidth\setlength{\ztextwidth}{530pt}  % Text width

\newlength\zitemmargin
\setlength{\zitemmargin}{\zimwidth+\zimmargin}

\newsavebox{\zitembox}
% Usage: \zitem{title}{body}{image.jpg}
\newcommand{\zitem}[3]{
\savebox{\zitembox}{\parbox{\ztextwidth-\zitemmargin}{%
\vspace{10pt}        % top inner margin
\textbf{\Large #1}
\vspace{5pt}\newline % title/text margin
\large #2
\vspace{10pt}        % bottom inner margin
}}
\settototalheight{\ztextheight}{\usebox{\zitembox}}
\begin{mdframed}[style=item,
singleextra={
% Crop image, rounding the left corners
\clip (\zimwidth,0pt) -- (\zimwidth, \ztextheight)
(0,0pt) -- (\zimwidth,0)};
% Scale image to fill both width and height
\node at (.5\zimwidth,.5\ztextheight) {
\includegraphics[max size={\zimwidth}{\ztextheight}]{#3}
}};
}]
\usebox{\zitembox}
\end{mdframed}
}

% Those marked with % are required to stay fixed
leftmargin=20pt,
rightmargin=20pt,
backgroundcolor=white,
innertopmargin=0,%
innerbottommargin=0pt,%
innerleftmargin=\zitemmargin,%
middlelinewidth=0pt,
font=\normalfont\large,