Making Figures in LaTeX

To make a figure in LaTeX is simpler than it looks and just requires a few commands.

  1. Use the graphicx package with the following command in the preamble:
          \usepackage{graphicx}
        
    Yes, there are others but this is the best and most widely used.
  2. Insert the figure: using the figure environment as follows:
          \begin{figure}[!htb]
            \center{\includegraphics[width=\textwidth]
            {figures/biotensor.png}}
            \caption{\label{fig:my-label} My figure.  An example of a cool figure}
          \end{figure}
        
    Figures in LaTeX are "floats", which means they can end up anywhere depending on how they fit, how big they are, and some advice we give the program. The [htb] part above advises LaTeX to put the figure "here" or at the "top" or "bottom" of the page, with that order of preference. The [width=] part allows you to tell LaTeX how wide to make the figure on the page; [height=] is also legal and there some others I always forget.
  3. Adjust figure placement: sometimes figures do not appear anywhere close to where you specify them so how can this happen?
    • One figure can be too large for a page, in which case it gets held with all the other figures until the end of the section and then they all get printed.
    • There can be too much figure and not enough text. LaTeX has rules about how much text it requires a page to have; it will push figures back until it meets those rules. To change the rules, use the following:
         %%%%%%%%%%%%%%%%%%%%%%%%%%%% Setting to control figure placement
         % These determine the rules used to place floating objects like figures 
         % They are only guides, but read the manual to see the effect of each.
         \renewcommand{\topfraction}{.9}
         \renewcommand{\bottomfraction}{.9}
         \renewcommand{\textfraction}{.1}
      	    
      The larger the first two parameters and the smaller the last one, the more a page can be filled with figures and the less has to be text.
  4. Prepare the figure file. With standard LaTeX, all figures must be in encapsulated postscript (eps) format but pdflatex allows pdf, png, jpg, and tiff formats but NOT eps. There are lots of tools for making figure files but note the following:
    • Only eps and pdf files support vector drawing and fonts; all other formats create a bit map, the resolution of which is sometimes an adjustable parameter within the program making the file. Bit-mapped images almost always have jaggy, ugly text.
    • Both eps and pdf files have "bounding boxes", that determine how much space a figure takes. If there is content outside the bounding box, it will be lost. If the bounding box contains lots of white space, it will also appear in the document.
    • To edit bounding boxes in eps files is often a manual process using, for example ghostview (gv) to find good coordinates and then hand-editing the file.
    • To edit bounding boxes in pdf: a) use Illustrator via the Document Setup menu to manually set the size (a black rectangle outline provides the visual feedback; or b) use Preview (Mac OSX) and click and drag a rectangle over the desired region.
  5. When the figure files is not ready then comment it out of the figure environment above and leave a placeholder:
    	\begin{figure}[htb]
    	%   \center{\includegraphics[width=\textwidth]
    	%       {figures/biotensor.png}}
    	  \vspace{3in}
    	  \caption{\label{fig:my-label} My figure.  An example of a cool figure}
    	\end{figure}
          
    Note: LaTeX complains about missing figures, but pdflatex exits immediately upon encountering one.
  6. Set the path for the figure files in the document with the command
       \graphicspath{{./figuresdir1/}{./figuresdir2/}{./figuresdir3/}}
          
    Note the somewhat odd syntax of specifying the directories--especially the closing
       "/",
    which is required. This command is completely optional but sometimes useful when figures are not close at hand or live in a central repository somewhere on your computer.

Last modified: Thu May 21 19:19:36 MDT 2015