Document 652

The LaTeX subfig package

Version: 5.5 - Scientific WorkPlace & Scientific Word

The subfig package supports the use of small figures and tables within a single floating figure or table environment. The package supersedes the subfigure package but isn't completely compatible with it.

The package supports the positioning, captioning, and labeling of small figures and tables and the inclusion of their captions in the list of figures or tables.

Several options, available through the Options and Packages command on the Typeset menu, define the placement and caption formatting of all subfigures and subtables in the document. The options are flexible and allow variations such as captions for both the entire figure and for each subelement, or a caption for the entire figure and only a label for each subelement. Commands in TeX fields in the document body define specific subfigures and subtables.

The package works with the caption package and uses its features for customizing caption layout. The package also requires the ragged2e package, which it calls automatically. Subfig should be compatible with other packages that modify or extend float environments.

Note that the instructions below differ slightly depending on the kind of file you create when you typeset. The Output Choice setting on the Typeset menu affects the way graphics are generated when you typeset a DVI or PDF file. When the Output Choice is set to DVI output, the program uses the original graphics files. When the Output Choice is set to PDF output or Both DVI and PDF output, graphics for the PDF file are generated when the document is saved. These graphics must be available when typesetting the main document to avoid LaTeX errors and missing graphics in the PDF file.

These instructions don't apply to portable LaTeX documents, because that document type doesn't use the FRAME macro that defines graphics.

The package is installed in the TCITeX/TeX/LaTeX/contrib/subfig directory. The file SWSamples/PackageSample-subfig.tex in your program directory illustrates the use of the subfig package. For more information, see the package documentation.

Creating subfigures or subtables with the subfig package

  1. Add the subfig package to your document and modify the subfig package options as necessary.

    Because the subfig package automatically calls the caption package, it isn't necessary to add the caption package to your document, but you may add it if you want to. If you do add the caption package, make sure it appears before the subfig package in the Packages in Use list.

  2. Create a floating environment for subfigures:

    1. Place the insertion point where you want the subfigures to appear.

    2. Enter an encapsulated TeX field.

    3. Type \begin{figure} to specify a floating graphics environment and press Enter.

    4. If you want a caption to apply to all the subfigures in the environment, type \caption{title} where title is the caption you want, and press Enter.

      This caption will appear in the list of figures for your document.

    5. If you want to create cross-references to the environment, type \label{x} where x is the key for the floating environment, and press Enter.

    6. Type \end{figure} and choose OK.

  3. From the Typeset menu, choose Output Choice and select the typeset output type you want (DVI output, PDF output, or Both DVI and PDF output) and choose OK.

  4. Prepare each subfigure:

    1. Open a new, completely empty document using the Blank - Standard LaTeX Article shell from the Standard LaTeX shell directory.

    2. From the File menu, choose Document Info and choose the Save Options tab.

    3. Uncheck Store Relative Graphics Paths and choose OK.

    4. From the File menu, choose Import Picture to import the graphic image you want as a subfigure.

    5. Choose Properties and then choose the Layout tab.

    6. In the Placement area, check In Line.

    7. Make any other modifications you need and then choose OK.

    8. From the Typeset menu, choose Output Choice and select the same output choice as for the main document, then choose OK.

    9. Save the document.

    10. Open the .tex file with an ASCII editor.

    11. Find the lines that represent the figure and copy them to the clipboard.

      The lines will appear differently depending on your output choice:

      • If you have chosen DVI output, the lines will have an appearance something like this:

        Code sample

      • If you have chosen PDF output, the lines will have an appearance like this:

        Code sample

      • If you have chosen Both DVI and PDF output, the lines will have an appearance like this:

        Code sample

  5. Return to your original SWP or SW document and reopen the encapsulated TeX field for the floating environment.

  6. Create the subfigure:

    1. Place the insertion point on a new line just below the \begin{figure} command.

    2. Type \subfloat[entry][caption] where entry is the subfigure caption as you want it to appear in the list of figures and caption is the subfigure caption as you want it to appear in the body of your document.

    3. Type {

    4. If you want to create cross-references to the subfigure, type \label{x} where x is the key for the subfigure.

    5. Press Enter and paste the lines representing the figure from the clipboard to the TeX field.

    6. Type } and choose OK.

  7. Repeat steps 4--6 for each subfigure in the floating environment.

  8. Create a floating environment for subtables:

    1. Place the insertion point where you want the subtables to appear.

    2. Enter an encapsulated TeX field.

    3. Type \begin{table} to specify a floating table environment and press Enter.

    4. If you want a caption to apply to all the subtables in the environment, type \caption{title} where title is the caption you want, and press Enter.

      The caption will appear in the list of tables for your document.

    5. If you want to create cross-references to the environment, type \label{x} where x is the key for the floating environment, and press Enter.

    6. Type \end{table} and choose OK.

  9. Prepare each subtable:

    1. Open a new, completely empty subdocument.

    2. From the Insert menu, choose Table.

    3. Specify the table size and alignment you want and choose OK.

    4. Fill the table with information, formatted as you want.

    5. Save the document.

    6. Open the .tex file with an ASCII editor.

    7. Find the lines that represent the table and copy them to the clipboard.

  10. Return to your original SWP or SW document and reopen the encapsulated TeX field for the floating environment.

  11. Create the subtable:

    1. Place the insertion point on a new line below the \begin{table} command.

    2. Type \subfloat[entry][caption] where entry is the subtable caption as you want it to appear in the list of tables and caption is the subtable caption as you want it to appear in the body of your document.

    3. Type {

    4. If you want to create cross-references to the subtable, type \label{x} where x is the key for the subtable.

    5. Paste the lines representing the table from the clipboard to the TeX field.

    6. Type } and choose OK.

  12. Repeat steps 9--11 for each subtable in the floating environment.

  13. Save and typeset compile your document.

Including subfigures and subtables in the lists of figures and tables

  1. On the Typeset toolbar, click frontmatter.wmf or, from the Typeset menu, choose Front Matter.

  2. Place the insertion point after the Make TOC field.

  3. Press Enter and apply the Remove Item Tag.

  4. Apply the Make LOF tag and choose OK.

  5. Apply the Make LOT tag and choose OK.

  6. From the Typeset menu, choose Preamble.

  7. On a new line at the end of the entries, type \setcounter{lofdepth}{2} to include subfigure captions in the list of figures or \setcounter{lotdepth}{2} to include subtable captions in the list of tables.

  8. Choose OK.

Last revised 11/28/06