99

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?

9
  • 7
    You cannot use a figure within a minipage. Remove the surrounding minipage.
    – Stefan Kottwitz
    Jul 17, 2013 at 6:16
  • 6
    Remove \begin{figure}[h!] and \end{figure}. Please include only \includegraphics[...]{...}.
    – Jagath
    Jul 17, 2013 at 6:17
  • 1
    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, 2013 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, 2013 at 6:29
  • 4
    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, 2013 at 6:42

4 Answers 4

67

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, so there may be other issues.

Let me run through your set-up to discuss several 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 your sample code need to be removed.

Next given that, many of the other constructs you use do not need to be encapsulated in a 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

to get horizontal spacing between objects.

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 using 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 text to the left. This is equivalent to \hspace{1em}. For the space between the first two blocks, I used \hspace{4em plus 1fill}, this is a minimum of four 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.

3
  • good answer. but \show\quad says \hskip 1em\relax, not 2em. \qquad is 2em wide.
    – jakun
    Apr 17, 2020 at 11:11
  • @jakun Thanks! - now fixed Apr 17, 2020 at 14:25
  • Thank you @AndrewSwann! I was trying to put a row of images, and a caption under them in the \maketitle section of a paper. \titlepic solves the placement part of that but it (for the same reason as minipage?) does not allow using a figure inside the brackets of \titlepic{} . Your answer is super helpful! Mar 7, 2023 at 22:41
24

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}
3
  • 1
    Just adding [H] worked for me whilst using minted. May 18, 2017 at 19:35
  • 1
    @RaffiKhatchadourian It is good practice to be explicit about your dependencies and load the packages you use. If minted stopped depending on float, your document would stop compiling and you may have no idea why.
    – Witiko
    Jun 24, 2022 at 19:32
  • Thank you! Worked for me. I had the same issue with the algorithm environment and this solved it. :) Jul 7, 2022 at 22:02
9

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
  • 2
    In my case, an \end{figure} was swallowed by an incomplete command that expected an argument. Jan 30, 2022 at 12:42
2

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}
1
  • 7
    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, 2014 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .