Graphics, Figures & Tablesmulticol | Figures inside a multi-columned Document

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
muath
Posts: 30
Joined: Thu Jul 15, 2010 11:34 am

multicol | Figures inside a multi-columned Document

Post by muath »

Hi there,

When I put a figure inside tow columns environment, it is not appeared and I get the following warning.
Floats and margins are not allowed inside multlcoulmns environment.
This is the code:

Code: Select all

\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{a4wide}

\begin{document}

\begin{multicols}{2}
aa
\begin{figure}
%  \centering
  \includegraphics[width=2.5cm] {cc.jpg}
  \caption{s}
  \label{fig:cc}
\end{figure}
\end{multicols}

\end{document}
Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
coachbennett1981
Posts: 269
Joined: Fri Feb 05, 2010 10:15 pm

multicol | Figures inside a multi-columned Document

Post by coachbennett1981 »

Have you tried this code:

Code: Select all

\documentclass[twocolumn]{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{graphics}


\begin{document}

aa
\begin{figure}
%  \centering
  \includegraphics[width=2.5cm] {cc.jpg}
  \caption{s}
  \label{fig:cc}
\end{figure}

\end{document}

muath
Posts: 30
Joined: Thu Jul 15, 2010 11:34 am

multicol | Figures inside a multi-columned Document

Post by muath »

coachbennett1981 wrote:Have you tried this code:

Code: Select all

\documentclass[twocolumn]{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{graphics}


\begin{document}

aa
\begin{figure}
%  \centering
  \includegraphics[width=2.5cm] {cc.jpg}
  \caption{s}
  \label{fig:cc}
\end{figure}

\end{document}
I do not need the complete article in two columns.
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

multicol | Figures inside a multi-columned Document

Post by localghost »

muath wrote:Hi there,

When I put a figure inside tow columns environment, it is not appeared and I get the following warning.
Floats and margins are not allowed inside multlcoulmns environment.
[…]
The warning says it all. Multi-columned environments simply don't allow floating objects. And that does not depend on whether you set up this environment by the twocolumn document class option or by the multicol package.

A possible solution is to use figures (and tables) at fixed positions without any float environment. For this purpose the caption package provides the \captionof command. The below code shows a short example derived from your code.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}   % Setup for page and paper dimensions
\usepackage{caption}
\captionsetup{
  font=small,
  labelfont=bf,
  tableposition=top
}
\usepackage{multicol}
\usepackage{graphicx}   % Use »demo« option for examples in questions on forums
\usepackage{lipsum}     % Create some dummy text, to be dropped in the actual document

\begin{document}
  \lipsum[1]
  \begin{multicols}{2}
    \lipsum[2]
    \bigskip
    \noindent   % Very important in case that \parindent is not 0pt
    \begin{minipage}{\linewidth}
      \centering
      \includegraphics[width=2.5cm]{cc.jpg}
      \captionof{figure}{Figure caption}
      \label{fig:cc}
    \end{minipage}
    \lipsum[3]
  \end{multicols}
  \lipsum[4]
\end{document}
For details please take a close look at the respective package manuals. To keep the figure and its caption together, an additional {minipage} environment has been used. Otherwise it can happen that they are split across column (or page) breaks.

By the way, the a4wide package is obsolete. You better use the geometry package along with the corresponding option a4paper for the document class to set up the page layout (see above code).

The lipsum package has only been used to create some dummy text, thus is not part of the solution and can be dropped in the actual document.
coachbennt1981 wrote:Have you tried this code:

Code: Select all

\documentclass[twocolumn]{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{graphics}


\begin{document}

aa
\begin{figure}
%  \centering
  \includegraphics[width=2.5cm] {cc.jpg}
  \caption{s}
  \label{fig:cc}
\end{figure}

\end{document}

It absolutely superfluous to load graphics because it is already loaded by graphicx. Furthermore this code won't work at all.


Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply