# automatically adjust the size of a minipage

I'm trying to get a way to automatically adjust the size of a minipage.

I am creating a report which will have several "paragraphs" that have a floating image on the left and some text on the right of that image. The both of them ( image + text ) make together a "semantic block".

First I did that :

\begin{wrapfigure}{L}{0.15\textwidth}
\centering
\includegraphics[width=0.1\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
Text not related to this image\\


and of course the text not related to the image was considered like the other lines of text, printing on the right of the image.

So i tried to wrap it all :

\begin{minipage}[c][10cm]{20cm}
\begin{wrapfigure}{L}{0.15\textwidth}
\centering
\includegraphics[width=0.1\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
\end{minipage}
Text not related to this image\\


but it really isn't convenient and the height is fixed.

Here is a minimal "working" code for both:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}

\begin{wrapfigure}{L}{0.2\textwidth}
\centering
\includegraphics[width=0.2\textwidth]{image}
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
Text not related to this image\\

\begin{minipage}[c][10cm]{20cm}
\begin{wrapfigure}{L}{0.2\textwidth}
\centering
\includegraphics[width=0.2\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
\end{minipage}
Text not related to this image\\

\end{document}


If there is a better way to do it not using minipage that would be great too. In the end i plan to make it into a \newenvironment taking 2 parameters : image name and text so I can use it easily in the article.

• Welcome. Your use of \\  tells me you are doing something strange. The doube backslash should only be used in tables, it is almost never needed in normal text. – Johannes_B Feb 19 '17 at 7:33
• Do you simply want to have a box with an image on the left and a description/caption on the right? That is very simple and wrapfigure isn't needed. I think it is a strange package anyway. – Johannes_B Feb 19 '17 at 7:34
• \\ is the same as \newline no ? I use it to make a linebreak. I made a little editing of a picture of what i want. In red is the text before and after the "box" i want to create. img11.hostingpics.net/pics/740360whatiwant.png – shrimpdrake Feb 19 '17 at 8:07
• Johannes_B added a minimal working example what we need to see to help you properly. – shrimpdrake Feb 19 '17 at 8:18

I am a big fan of floating environments, but if floating is not allowed, you don't have to use it.

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{blindtext}
\newcommand{\nonfloatingfigure}[3]{%
\noindent\begin{minipage}{\linewidth}
\begin{minipage}{.5\linewidth}
\centering
#1\par#2\end{minipage}\begin{minipage}{.5\linewidth}
\raggedright#3
\end{minipage}
\end{minipage}
}
\begin{document}
\blindtext

\nonfloatingfigure{\includegraphics[width=0.6\textwidth]{example-image-a}}{
image caption with no "figure1"}{
The image on the left shows a Wombat, well it would, but package MWE does not provide
a picture of a Wombat. It definitely should

}
\blindtext

\nonfloatingfigure{\includegraphics[width=0.4\textwidth]{example-image-b}}{
image caption with no "figure1"}{
Text related to this image
Text related to this image
\blindtext
}
Text not related to this image
\blindtext

\end{document}

• exactly what i needed. Clever to use two adjacent minipages inside a big minipage. I adapted it ( \usepackage{calc} needed ) to get the left one {4cm} and the right one {\linewidth-4cm}, it works great. – shrimpdrake Feb 19 '17 at 9:45
• @shrimpdrake Nice to hear it works for you. – Johannes_B Feb 19 '17 at 9:47