Aug.01

Adding Figures to LaTeX Manuscripts

Adding Figures to LaTeX Manuscripts

One common complaint is that LaTeX is not image-friendly and is somewhat true. Depending on the workflow being used the format of the image is quite important. I am by no means an expert in TeX and have only compiled this information searching through forums whenever stuck on a certain problem. I must confess that despite the initially steep learning curve (compared to Word and others), I am pleased that I kept carrying on using LaTeX because the end result is absolutely beautiful!

If you are using pdflatex for compiling then there are more options such as JPG, PDF, EPS, PNG. If using latex, then your only choice is using the EPS format. My workflow is LaTeX -> DVI -> PDF so all images are in EPS format. I’d suggest using vector graphics (PDF or EPS images) anyway because they scale nicely unlike JPG images.

Because I am constrained to using EPS images I have to convert the files if they are in any other format – and this happens very often. At first this was frustrating but after couple of years of using the same workflow I think I have settled in nicely. On my Windows machine I use TeXnicCenter while on my Mac I have a script that compiles using latex in pretty much the same way.

Which file format?

When I am creating a flowchart or block diagram of something I prefer using Adobe Illustrator of Microsoft Visio. Illustrator allows me to save as EPS directly and with Visio I save the file as PDF (more on PDF to EPS conversion later).

My plots and graphs are generated using Matlab which allows me to use the excellent LaPrint function directly. This function will save two files, an EPS image and a TEX file, the latter will need to be sourced in your main manuscript (see below for example).

For any other image files I save them as PDF using Preview in OS X (I am sure it can be saved as easily on Windows too).

Converting from PDF to EPS

This is the part that is not so easy unless you have Adobe Acrobat Professional. I open all my PDFs in Acrobat Professional and just export them as EPS. I haven’t looked yet if there is a way of automating this with a script but that would make the whole process of JPG->PDF->EPS much quicker.

If you don’t have Acrobat Professional I think you’re better off using pdflatex with PDF images.

The Preamble

To insert the figure in your paper, first you need to add this to your preamble:

\usepackage{graphicx}

For Matlab generated plots using LaPrint, you will also need the psfrag package (you can read more about it here) and the color package to add colour to your text.

My preamble looks like this with all three packages:

\usepackage{graphicx,psfrag,color}

Inserting EPS Images

And now to insert a figure in the manuscript you just need to use \includegraphics{} :


\begin{figure}
\centering
\includegraphics[width=0.45\textwidth]{figure_name.eps}
\caption{Caption of the figure.}
\label{fig:label}
\end{figure}

I add the \centering tag because it looks nicer when figures are centered! And the width is set to 0.45*textwidth to keep it just within the margin of a two-column paper where each column is half of the total text width.

Note that if you want the figure to span both the columns of a two-column paper you don’t need to point your cursor to the edge of the figure, resize it, realign it and then work with the text around it (as you’d do with MS Word, for example). Just add an asterik to the end of figure begin and end, as below:


\begin{figure*}
\centering
\includegraphics[width=0.45\textwidth]{figure_name.eps}
\caption{Caption of the figure.}
\label{fig:label}
\end{figure*}

Inserting Matlab Images (LaPrint)

The files generated using LaPrint for Matlab figures can be easily sourced in using the following code:


\begin{figure}
\centering
\input{matlab_figure.tex}
\caption{Matalb figure caption.}
\label{fig:label}
\end{figure}

Adding group of figures or subfigures

That’s all quite easy but what about subfigures? Exactly the same procedure, with the addition of using the subfigure package.

\usepackage{subfigure}

In the body of the manuscript, the following code will generate five subfigures, two on each of the first two lines and one on the last one, all centered, spanning the two columns.


\begin{figure*}
\centering
\subfigure[]{\label{fig:fr1}\includegraphics[width=0.48\textwidth]{images/sp1.eps}}
\subfigure[]{\label{fig:fr2}\includegraphics[width=0.48\textwidth]{images/sp2.eps}}
\subfigure[]{\label{fig:fr3}\includegraphics[width=0.48\textwidth]{images/sp3.eps}}
\subfigure[]{\label{fig:fr4}\includegraphics[width=0.48\textwidth]{images/sp4.eps}}
\subfigure[]{\label{fig:fr5}\includegraphics[width=0.48\textwidth]{images/sp5.eps}}
\caption{Five subfigures!}
\label{fig:subfigure_example}
\end{figure*}

Rotating Images

I am pretty sure there is a package that allows rotating images very easily but I can’t be bothered to look for it. For quite some time now, I rotate the image beforehand in Preview (or any other image viewer) before inserting it in my manuscript. I find this much easier but feel free to search if you want a more TeX-y solution.

That’s pretty much all about adding images. In the coming weeks I will post about inserting tables and equations and some tips and tricks that I’ve collected over the years that is helpful when writing papers and theses.

 

Cover Image Source: The Unconditional Blog

Uncategorized
Share this Story:
  • facebook
  • twitter
  • gplus

About anasimtiaz

Comments(1)

  1. Adam
    1075 days ago

    Thanks a lot! Very useful.

Leave a comment

Comment