Putting Figures in LaTeX Documents
Figures are known as floating bodies as they float to the most suitable place rather than necessarily appearing exactly in the text where you put the commands. There are essentially 2 main ways of including figures you should know.
If you have created an encapsulated postscript picture using another packages (e.g. Maple, Matlab, xfig) you can include it in your LaTeX with commands of the form
which tells LaTeX to put the figure here or at the top of the next page, gives it a caption and a label for later use to produce cross references. For this to work at the beginning of your LaTeX include the epsfig package, e.g. you need a line
Figures with LaTeX onUsing xfig you can draw figures and write on them using LaTeX. Other packages can also put LaTeX on to their output, e.g. Mathematica. Matlab can only fake very basic LaTeX and so it is best to use xfig to draw on graphs produced in most other packages.
Once you have drawn/generated a figure in xfig with LaTeX comands on it you can include it in your LaTeX document with commands of the form
How to put LaTeX on Xfig pictures
- In xfig draw your picture.
- Add the text: when you click on the text button (the T) lots of options appear at the bottom of the screen. The really important one is the one marked Text Flags. Click on this and change the option Special Flag from normal to special. Now any text you write on the figure is magically marked. You can write text as if it were LaTeX, e.g. you could put $\alpha$ to put an alpha on the picture etc.. If you add the text and forget to set the flag you can set it later on pieces of text by using the edit button and clicking on the text. This produces a window of options of which one is the special flag which you can set to special.
(If you always want xfig text to be special you can add the line
to your .Xresources file.)
- Having drawn the picture and added the LaTeX text save the figure using the file button at the top. Name the file something like myfile.fig
- Export the figure: Because the figure contains special text you need to export it in 2 pieces. Clicking on the export menu will bring up a box of options. You need to choose to export it as
Combined PS/LaTeX (both parts)
(not Encapsulated postscript).
This should create 2 files called myfile.pstex and myfile.pstex_t and these are what are used in your latex. However don't delete the .fig file as that is what is needed by xfig if you wish to re-edit the picture.
Note when you select a tool in xfig at the top right a window displays what each of the mouse buttons will do (once you move the mouse over the canvas).
Note the file myfile.pstex is a postscript file and contains the `picture' part of the figure. The file myfile.pstex_t is LaTeX and contains the text part and also contains a line to include the picture part. By default both these files would have to be in the same directory as your LaTeX in order for LaTeX to find them. However it is possible to put them in other directories to make things clearer. By using a command of the form
near the beginning of your LaTeX you can instruct LaTeX to look in other directories for postscript files. The above example says to look in this directory and the subdirectory called Figs.
Furthermore, on the Maths network, if you put all your LaTeX files in subdirectories of a directory called ~/TeX then they will be automatically found.
Thus with both these features both parts of the exported figure can be found even if they are not in the same directory as the LaTeX.
WARNING xfig would appear to have a bug that causes it to calculate the positioning of the text in the output file incorrectly when using centimetres, using inches it all works fine. To make it use inches by default add the line
to your .Xresources file. Some other useful options for the .Xresources file are
An alternative approach to using xfig is to use the psfrag package.