0

I am unable to insert an image using the code below. The actual image is in .eps format and in the same directory as my .tex file. I've tried .jpeg and .png to no avail.

\documentclass{article}
\usepackage{multicol}
\usepackage{tgbonum}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{chemfig}
\usepackage{siunitx}
\usepackage[super]{natbib}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{epstopdf}

\geometry{
     a4paper,
     total={170mm,257mm},
     left=20mm,
     top=20mm,}
    \begin{document}

    \section{Introduction}

    \begin{multicols}{2}

    \begin{figure}
    \includegraphics[width=\linewidth]{./xyz.eps}
    \caption{X-ray crystal structure of x}
    \label{fig:boat1}

    \end{figure}
    \end{multicols}

    \end{document}
3
  • 1
    multicols environment doesn't allows to insert floats. why you use it? isn't twocolumns option of article sufficient?
    – Zarko
    Jun 14, 2018 at 14:00
  • @Zarko should I replace the \begin{multicols}{2} with \twocolumns?
    – Hazinga
    Jun 14, 2018 at 14:05
  • 1
    i don't know how you like to design your article. i suspect that \documentclass[twocolumn]{article} should gives what you like to achieve. and not use multicol package and its environment.
    – Zarko
    Jun 14, 2018 at 14:30

2 Answers 2

0

mulitcol can handle floats using the following amendments. Picture appears under these circumstances.

\documentclass{article}
\usepackage{graphicx,float}

\begin{document}
\multicols{2}

\begin{figure}[H]
\centering
\includegraphics[width=3cm]{mypicture}
\caption{caption for mypicture}
\end{figure}

\end{document}
3
  • Your example does not compile. It gave the following error: ! Undefined control sequence. l.17 \multicols{2}, I was left with the idea that you proposed ammendments to multicol. What are those amendments?
    – djnavas
    Jun 15, 2018 at 5:52
  • @djnavas the key was to add the [H] after the \begin{figure}. Without [H] the picture doesn't appear
    – Hazinga
    Jun 15, 2018 at 11:00
  • LaTeX requiere a minimum percentage of space dedicated to text and a maximum to floats. Your example does not have text. Therefore, where the float should go? Also, I added the package multicol (\usepackage{multicol}) and this is required to compile your example.
    – djnavas
    Jun 16, 2018 at 9:44
0

The multicols environment is handy because it let you mix multi-column environments but it doesn't allow adding floats. I am not 100% certain but some time ago I came across a post where wrapfig package with its wrapfigure environment could be a workaround.

If you are OK to mix images with texts without using floats and workout space by yourself, you could just put each image in the minipage environment. This idea is not entirely mine. Beware though! It's very likely LaTeX will leave empty space if it can't fit images around page or column edges and you have to rearrange texts to find the most optimal image placement.

The MWE

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{kantlipsum}
\usepackage[english]{babel}
\usepackage{geometry}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{multicol}

%%% Macro just for this MWE to avoid repetitions
%   \examplefigure[#1]{#2}{#3}{#4}
%
% #1 a number relative to \linewidth (optional)
% #2 file name e.g. example.eps
% #3 Text for a caption
% #4 Label
\newcommand{\examplefigure}[4][0.65]{%
    \vspace{1em}
    \noindent\begin{minipage}{\linewidth}%
        \makebox[\linewidth]{%   For centring figures
            \includegraphics[width=#1\linewidth]{#2}}
        \captionof{figure}{#3}
        \label{#4}
    \end{minipage} 
    \vspace{0.5em}}


\begin{document}

\section{Section 1 (no columns)}

\kant[1]

\section{Section 2 (two columns)}

\begin{multicols}{2}
    \kant[2][1-2]
    
    \examplefigure{example.eps}{Figure in columns}{fig:label1}

    \kant[2]\par\kant[3]\par\kant[4][1-5]

    \examplefigure{example.eps}{Figure in columns}{fig:label2}

    \kant[4][1]
    
\end{multicols}

\section{Section 3 (No columns)}

\kant[5][1-2]

\examplefigure[0.75]{example.eps}{The big figure}{fig:label3}

Reference to figures \ref{fig:label1}, \ref{fig:label2}, and \ref{fig:label3}.

\end{document}
Page 1 Page 2
enter image description here enter image description here

You must log in to answer this question.

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