This is a collection of short LaTeX tips that I picked up during the writing of my thesis and various journal articles and papers.
For regular floats such as tables and figures, the caption position can be set to above or below the float by simply issuing the caption command above or below the float contents.
For subfloats using the subfig
package, the caption position is controlled by the \captionsetup
command of the \caption
package. The subfig
documentation was a bit confusing about this but \captionsetup
can be used as follows. First, include the caption package:
\usepackage{caption}
Then, issue a \captionsetup
command, either right after \usepackage{caption}
or just before the figure or table for which you want to control the subcaption position:
\captionsetup[FLOAT_TYPE]{position=POSITION}
FLOAT_TYPE
can be subfigure or subtable for controlling the caption position for the corresponding type of float. POSITION can be top
or bottom
.
The following code will put the subcaptions on top of the subfigures (remember to replace placeholder
with the name of a graphic file that you want to include):
\captionsetup[subfigure]{position=top} \begin{figure}[tbp] \centering \subfloat[Caption 1]{\includegraphics[width=1in]{placeholder}}\quad \subfloat[Caption 2]{\includegraphics[width=1in]{placeholder}} \caption{Main figure caption.} \end{figure}
The result is this:
The default is to put the caption below the subfigure, but you can explicitly specify this by changing the \captionsetup
command:
\captionsetup[subfigure]{position=bottom}
The result will look like this:
See my other page on LaTeX captions for more you can do to customize and style them.
The enumerate
package gives more control over enumerations. Include the package in your LaTeX document:
\usepackage{enumerate}
You can then control how the numbering or lettering occurs by specifying a format argument when starting an enumeration:
\begin{enumerate}[FORMAT]
FORMAT
is a user defined string. Special characters specify the numbering or lettering convention, while any other characters are taken as normal LaTeX code that is reproduced for each item. The special characters are:
Special Character | Enumeration Style |
---|---|
A | Upper case letters |
a | Lower case letters |
I | Upper case Roman numerals |
i | Lower case Roman numerals |
1 | Arabic numbers |
The following produces lower case Roman numerals with a ”)” after it:
\begin{enumerate}[i)] \item This is an item. \item This is an item. \end{enumerate}
The above code will produce this:
The following produces lettering of the form “Item A:”
\begin{enumerate}[{Item} A:] \item This is an item. \item This is an item. \end{enumerate}
The above code will produce this:
Note that since “Item” contains a special character (I
) of the enumerate
package, it is written inside a { }
clause. This tells the package to ignore the “I” as a special character.
You can also put other LaTeX code in the format string, such as an \hspace
:
\begin{enumerate}[\hspace{1cm}1)] \item This is an item. \item This is an item. \end{enumerate}
Depending on your document class, the table of contents sometimes does not automatically have entries for some parts of the document, especially if they are not formally declared as \chapter
, \section
, etc. For example, in my thesis, the List of Figures did not automatically have an entry included in the table of contents. I was able to manually include the List of Figures entry with the following:
\cleardoublepage % Start a new page for the list of figures. Make it right handed for two-sided documents. \phantomsection % ensure that the hyperlink in TOC to this section is correct. \addcontentsline{toc}{chapter}{List of Figures} % add to table of contents. \listoffigures % generate the list of figures.
The first three lines of code create the proper List of Figures heading and puts it into the table of contents, while the last line generates the List of Figures itself and is unrelated to the task of adding entries to the table of contents. The first three lines of code can be broken down as follows:
\cleardoublepage
puts the LOF on a new page, right handed if printing two-sided. This command is needed only if you intend to add the new entry as a chapter in the table of contents.\phantomsection
is needed if you use PdfTeX with the hyperref
package and you specified the bookmarks
option for hyperref. This allows the hyperlink in the TOC to link to the appropriate place in the document.\addcontentsline
is used to add the entry into the table of contents.
You can add chapters, sections, etc. to the TOC by modifying the code above. Sections do not need \cleardoublepage
and you will need to change \\addcontentsline
to add a “section” instead of a chapter. An example of a section that you would need to add yourself to the TOC might be an unnumbered section, which is defined in the document as a \section*
rather than \section
.
If you want a page break in the table of contents, you can add a “section” in your document which gets turned into a page break when the table of contents is created. Just insert the following line:
\addtocontents{toc}{\protect\newpage\protect}
The line above should be inserted in your document content, just like \section
commands.
Discussion