TransWikia.com

! LaTeX Error: Not in outer par mode

TeX - LaTeX Asked on April 26, 2021

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]{.98linewidth}

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

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

 begin{minipage}[t]{0.4linewidth}
  begin{minipage}[t]{0.5linewidth} textbf{Some text} end{minipage}
  begin{minipage}[t]{0.25linewidth} begin{figure}[h!]   includegraphics[width=1.0textwidth]{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?

5 Answers

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

ahspace{...}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.4linewidth}
   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]{.98linewidth}
  begin{minipage}[t]{0.33linewidth}
    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.2linewidth}
    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.2linewidth}
    vspace{-2ex}
    includegraphics[width=1.0linewidth]{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{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.

Answered by Andrew Swann on April 26, 2021

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}

Answered by André on April 26, 2021

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.48textwidth} 
begin{figure}[H]
caption{label{fig:label} Figure title}
includegraphics[width=textwidth]{filename}
end{figure}
end{minipage}
end{document}

Answered by Adenilton on April 26, 2021

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.)

Answered by Vincent on April 26, 2021

In my case, a stupid slip in a tabular header was the problem:

begin{tabular}{l|D..{0]}

Obviously, there should be a brace instead of a bracket ... ?

Answered by Christoph Thiede on April 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP