54

I am using an image within minipage and getting error message.

  ! LaTeX Error: Not in outer par mode.

Below is minimal working example.

\documentclass[11pt,table,a4paper]{article}
\usepackage{array,ragged2e}
\usepackage{graphicx}
\usepackage[top=2cm, bottom=3cm,right=1cm, left=1cm, headsep=26pt]{geometry}
\usepackage[T1]{fontenc}
\usepackage{sidecap}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}           
\begin{minipage}[t]{.98\linewidth}

\begin{minipage}[t]{0.33\linewidth}
 ABC
\end{minipage}

\begin{minipage}[t]{0.05\linewidth}
  \hspace{2cm}
\end{minipage}

 \begin{minipage}[t]{0.4\linewidth}
  \begin{minipage}[t]{0.5\linewidth} \textbf{Some text} \end{minipage}
  \begin{minipage}[t]{0.25\linewidth} \begin{figure}[h!]   \includegraphics[width=1.0\textwidth]{risk2.png} \end{figure} \end{minipage}
\end{minipage}             % Error is due to using figure in minipage

\end{minipage}
\end{document}             % End of document.

enter image description here

How can I fix this problem?

  • 4
    You cannot use a figure within a minipage. Remove the surrounding minipage. – Stefan Kottwitz Jul 17 '13 at 6:16
  • 4
    Remove \begin{figure}[h!] and \end{figure}. Please include only \includegraphics[...]{...}. – Jagath Jul 17 '13 at 6:17
  • As Jagath AR says, there is no need to put \includegraphics in a figure environment. TeX sees \includegraphics[...]{...} just like a big letter. – egreg Jul 17 '13 at 6:25
  • If i remve this i cannot use caption and also text which is adjacent in next minipage seems to be hanging down. – manish Jul 17 '13 at 6:29
  • 3
    Load caption (\usepackage{caption}) and use \captionof{figure}{your caption} to get caption outside figure environment. \captionof command is also provided by capt-of package – user11232 Jul 17 '13 at 6:42
38

Firstly to summarise the comments: figure environments may not appear in minipages. figure is a floating environment, but you want to place your graphics in a particular place. In principle all you need is the \includegraphics, but as you notice you do not get the vertical space you expect there may be other issues.

Let me run through your set-up to discuss a number of points.

Each minipage produces a box of typeset material and these are placed essentially like individual characters you enter. In particular, blank lines between minipages will start new paragraphs and thus not stay on the same line. So many of the blank lines in you sample code need to be removed.

Next given that, many of the other constructs you use do not need to be encapsulated in minipage. This applies in particular to the \hspace command. You can just write

\begin{minipage}...\end{minipage}\hspace{...}\begin{minipage}...\end{minipage}

as you would write

a\hspace{...}b

Similarly an image can be included directly, the \includegraphics command produces another box of typeset material that is again placed much like a character. You can use \raisebox to adjust its vertical placing if necessary.

On the other, hand if you are using figure because you wanted to have a caption and figure number available, then a minipage to include this and the caption would be appropriate. You can then use the caption package, which as \captionof command:

\begin{minipage}[t]{0.4\linewidth}
   \vspace{-2ex}
   \includegraphics{...}
   \captionof{figure}{Caption}
\end{minipage}

Note the use of a \vspace before the graphics; without it the first line of the minipage is very high, but the [t] option aligns on the baseline of the first line of the minipage so the image sticks up. -2ex is essentially the height of a capital letter, and will place the image so its top edge aligns with those. See Aligning image and text on top, with minipages for further discussion of such alignment of images in minipages.

Here is a modified version of your example putting these things together (irrelevant packages have been stripped out):

Sample output

\documentclass[11pt,a4paper]{article}

\usepackage{graphicx,caption}
\usepackage[top=2cm, bottom=3cm,right=1cm, left=1cm, headsep=26pt]{geometry}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}

\begin{minipage}[t]{.98\linewidth}
  \begin{minipage}[t]{0.33\linewidth}
    \setlength{\parindent}{1em}
    Some text over several lines.  
    Some text over several lines.  

    Some text over several lines in a new paragraph.
  \end{minipage}
  \hspace{4em plus 1fill}
  \begin{minipage}[t]{0.2\linewidth}
    \setlength{\parindent}{1em}
    Some text over several lines.  
    Some text over several lines.  

    Some text over several lines in a new paragraph.
  \end{minipage}
  \quad
  \begin{minipage}[t]{0.2\linewidth}
    \vspace{-2ex}
    \includegraphics[width=1.0\linewidth]{example-image-a}
    \captionof{figure}{Caption}
  \end{minipage}
\end{minipage}

\end{document}

I have used \quad to space off the image minipage from the that for the text to left. This is equivalent to \hspace{2em}. For the space between the first two blocks, I used \hspace{4em plus 1fill}, this is a minimum of two quads but stretches to fill out the available room. The effect here is that your first minipage is flushleft, and the last pair is pushed flushright.

In the minipages I set the paragraph indents, they are zero by default.

Note that minipage is quite a complex construct. It is appropriate if the material is long and includes several paragraphs. If it is just a single paragraph then \parbox is a better choice. See \parbox vs. minipage: Differences in applicability for a discussion.

8

Add \usepackage{float} and use the option [H] in the figure.

\documentclass{article}
\usepackage{graphicx}
\usepackage{float} %figure inside minipage
\begin{document}
\begin{minipage}{0.48\textwidth} 
\begin{figure}[H]
\caption{\label{fig:label} Figure title}
\includegraphics[width=\textwidth]{filename}
\end{figure}
\end{minipage}
\end{document}
4

The following is obviously not the source of your problem, but since it causes the same error, and this page is the first google hit for that error, I feel it might be useful for future readers to record it here anyway, if that's ok. So:

the

 ! LaTeX Error: Not in outer par mode.

can also be caused by forgetting to type an \end{table} a couple of lines higher.

(Normally this would of course be detected by a \begin{table} on line xxx followed by \end{document} error, but in my case the large number of outer par mode errors caused an emergency stop before getting there.)

1

Add \usepackage{float} and put the minipage (with grphics) inside figure.

\begin{figure}
\begin{minipage}
\begin{figure}
...
\end{figure}
\end{minipage}
\begin{minipage}
\begin{figure}
...
\end{figure}
\end{minipage}
\end{figure}
  • 4
    Welcome to TeX.SX! How does this solve the answer? A little more code and a full example would be of more use – user31729 Nov 7 '14 at 13:22

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.