20

I want to add an image to my paper but I have a problem.

When I add the image with just \includegraphics[]{} tag, everything works fine, and the picture shows up when I compile my document.

When I use \begin{figure} \includegraphics[]{} \end{figure} - syntax the image does not appear in the compiled document.

The relevant part of my header include is :

 \usepackage{graphicx}
 \graphicspath{ {pics/} }

And later on I add the image with this block:

%This does not work

\begin{figure}
  \centering
    \includegraphics[width=.4\textwidth]{generalPolya}
  \label{generalPolya}
\end{figure}



%This works

\includegraphics[width=.4\textwidth]{generalPolya}

I guess it's some sort of issue in the graphics package, but I've copied the setup from a previous paper I had, so it should work. Any ideas on what's wrong? Thanks in advance.

Edit:

Thanks for all the responses. I created a minimal working example. Apparently multicols messes with the figure tag:

\documentclass[]{article}
\usepackage{multicol} % Used for the two-column layout of the document
\usepackage{amsmath}
\usepackage{graphicx}
\graphicspath{ {pics/} }
\title{\vspace{-15mm}\fontsize{24pt}{10pt}\selectfont\textbf{Lorem ipsum}} % Article title
\begin{document}
\maketitle % Insert title
\begin{multicols}{2} %
%This does not show up
\begin{figure}[h]
    \includegraphics[width=.4\textwidth]{generalPolya}
\end{figure}
%This shows up.
\begin{center}
        \includegraphics[width=.5\textwidth]{chair}
\end{center}
\end{multicols}
\end{document}

What shows up after compiling the document is this

enter image description here

What is wrong with this syntax?

6
  • 1
    Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it).
    – user31729
    Jul 14, 2015 at 7:32
  • 2
    And additionally: Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jul 14, 2015 at 7:32
  • Your \label in the first code snippet is of no use, since it does not generate a label for your figure -- you have to use \caption for a \label to be effective there. Here you generate a label for the last counter incremented outside of the figure environment, e.g. a chapter counter
    – user31729
    Jul 14, 2015 at 7:33
  • 3
    Are you sure the float did not just float to a different page? you might also want to use \begin{figure}[htbp] as the default (\begin{figure}) is the same as \begin{figure}[tbp] note no h (remember h does not mean HERE, it means here about)
    – daleif
    Jul 14, 2015 at 7:35
  • 2
    @PanagiotisChatzichristodoulou: multicols disables the figure environment, such that nothing shows up
    – user31729
    Jul 14, 2015 at 8:38

6 Answers 6

11

Try using a minipage as this:

\documentclass[12pt,a4paper]{article}
\usepackage{caption}
\usepackage{graphicx}
\begin{document}

\makebox[0pt][l]{%
\begin{minipage}{\textwidth}
\centering
    \includegraphics[width=.4\textwidth]{example-image.pdf}
 \captionof{figure}{figure caption}
 \label{fig:fig1}
\end{minipage}
}

\medskip

I used Figure \ref{fig:fig1} above and referred to it.

\end{document}

enter image description here

3
  • 2
    Thanks for the response. What you suggest works, so I'll accept the answer. I still don't understand why this and a simple \includegraphics work, but the figure environment does not compile. Jul 14, 2015 at 7:57
  • @PanagiotisChatzichristodoulou: It will remain a mystery if you don't provide the faulty document which caused the error ;-)
    – user31729
    Jul 14, 2015 at 7:58
  • What's the point of including the makebox and mintage environments? Aug 10, 2020 at 14:54
20

This is why I like compiling on the command line and not with TeXMaker etc. stuff:

There is a clear warning in the .log file (and a often occurring error:) No floats inside multicols environment:

Package multicol Warning: Floats and marginpars not allowed inside `multicols' environment!.

This is documented behaviour, the multicol manual describes this warning and clearly states what will happen (emphasis mine):

Floats and marginpars not allowed inside ‘multicols’ environment!

This message appears if you try to use the \marginpar command or an unstarred version of the figure or table environment. Such floats will disappear!

If a figure (or table) with caption shall be used in a multicols environment, then use \captionof{figure}{Caption text} instead of \caption and omit the figure environment completely (or the table env.) In this sense, my answer is basically the same as the solution by AboAmmar, but without the box and minipage.

\documentclass[]{article}
\usepackage{multicol} % Used for the two-column layout of the document
\usepackage{amsmath}
\usepackage{caption}
\usepackage[demo]{graphicx}
\graphicspath{ {pics/} }
% I disable this since it's not relevant
%\title{\vspace{-15mm}\fontsize{24pt}{10pt}\selectfont\textbf{Lorem ipsum}} % Article title
\begin{document}
%  \maketitle % Insert title
\begin{multicols}{2} %
%This does not show up
%\begin{figure}[h]  % Drop this
    \includegraphics[width=.4\textwidth]{generalPolya}
    \captionof{figure}{My figure which should be inside the multicols}
%\end{figure} % Drop this
%This shows up.
\begin{center}
        \includegraphics[width=.5\textwidth]{chair}
\end{center}
\end{multicols}
\end{document}
1
  • 1
    Hope you don't mind my edit. Jul 14, 2015 at 8:44
2

I had a similar issue with a figure not showing up when using multicol

I fixed with the help of this answer: https://tex.stackexchange.com/a/483689/152952

\usepackage{float}
[...]
\begin{figure}[H]
    [...]
\end{figure}
1

This is the thread that came up when I was looking for the same problem.

My issue was that I had defined the document class as:

\documentclass[a4paper,11pt,draft]{article} 

Removing the draft part finally allowed the images to show.

1
  • 1
    This would not match OP symptom of the graphic appearing when not used in the figure environment.
    – Teepeemm
    Jul 2, 2021 at 12:07
0

I had a similar problem trying to get a fig. showing in a PDF pre-view in LaTeX Workshop (Vscode). I couldn't get it to show no matter what scale I chose. No error messages occured, and I couldn't see any corresponding warnings in the log. But once I closed the preview and reopened it, all of a sudden the fig showed. Im thinking it was compiling all the time, but somehow the PDF preview wasn't able to show it. A simple reopening did the trick for me. Maybe this helps someone too.

0

Similar to Pablo, this thread came up while troubleshooting a similar issue.

For those using Overleaf - if a custom draft option is available in a document class it might be worth checking if it conflicts with Overleaf's Fast option (See picture). In my case setting draft = true, draft = false or enabling Fast mode were all different, with the Fast option preventing any image from showing. enter image description here

1
  • As explained in other answers, problem is use of floats inside multicols environment. So, you not solve OP problem ...
    – Zarko
    Jul 20, 2022 at 13:15

You must log in to answer this question.

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