http://www.peteryu.ca/tutorials/publishing/latex_captions
Formatting captions and subcaptions in LaTeX
THE captions for figures, tables, subfigures and subtables in LaTeX can be customized in various ways using the caption
andsubcaption
packages. You can change the fonts, numbering style, alignment and format of the captions and the caption labels. A basic article class document has figure and subfigure captions that look like this:
The letters and numbers (“a”, “b” and “1”) that enumerate the captions and subcaptions are caption labels. In the above, the subfigure caption label is enclosed by parentheses and the figure caption label is separated from the caption text by a colon. This page will go over a few examples of how to change these and other aspects of the captions, including the numbering or lettering style (arabic, alphabetical or Roman numerals), the caption position and how to get captions with no label (i.e. no number and no letter).
The examples on this page use the \caption
and \subcaption
packages. I also have an older page which has examples using the deprecated subfig package. It is recommended to use the examples on this page; the older page is kept for reference and previous reader comments.
Getting started
To use the examples in this page, you will need the caption
package and also the subcaption
package (if you are working with subfigures or subtables):
\usepackage{caption} \usepackage{subcaption}
For reference, the code that produces the figure shown in the introduction is:
\begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Caption 1}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Caption 2}\label{fig:1b} \end{subfigure} \caption{Main figure caption}\label{fig:1} \end{figure}
The label
commands allow you to generate a cross-reference in the text to the figure. The label commands assigns a name that you can reference later, which will automatically be filled with the figure or subfigure number or letter. See the section on cross references.
To create a table with two subtables, the code is very similar, except you can replace the figure
environment with table
andsubfigure
with subtable
:
\begin{table} \centering \begin{subtable}[t]{2in} \centering \begin{tabular}{|l|l|l|} \hline 100 & 200 & 300\\ \hline 400 & 500 & 600\\ \hline \end{tabular} \caption{Caption 1}\label{table:1a} \end{subtable} \quad \begin{subtable}[t]{2in} \centering \begin{tabular}{|l|l|l|} \hline 100 & 200 & 300\\ \hline 400 & 500 & 600\\ \hline \end{tabular} \caption{Caption 2}\label{table:1b} \end{subtable} \caption{Main table caption}\label{table:1} \end{table}
Both subfigure
and subtable
environments allow you to specify their width. This controls how much space is “reserved” for their contents. You can replace the width with \columnwidth
to make it the column width of your document. Other values are possible.
Set caption label numbering style
You can change the numbering or lettering style of the caption label by using variants of the following commands in your document:
% change the style of the caption numbering. \renewcommand{\thetable}{\alph{table}} \renewcommand{\thefigure}{\Alph{table}} \renewcommand{\thesubtable}{\Roman{subtable}} \renewcommand{\thesubfigure}{\arabic{subfigure}}
Each command specifies the label you want to modify (e.g. \thetable
) and what you want to appear as the label (e.g.\alph{table}
, which means to show the table counter as a lower case letter like a, b, c, etc.). Each type of float has its own label (\thetable
) and counter variable (table
). Anything that appears after you issue these commands will have the new label numbering / lettering style.
There are five ways you can show the counters (replace counter
with the actual counter you want to show, such as table
):
Counter style | Code | Example |
---|---|---|
Arabic numerals | \arabic{counter} | 1, 2 |
Lower case letters | \alph{counter} | a, b |
Upper case letters | \Alph{counter} | A, B |
Lower case Roman numerals | \roman{counter} | i, ii |
Upper case Roman numerals | \Roman{counter} | I, II |
Here is an example of changing the figure and subfigure caption label numbering / lettering:
\renewcommand{\thefigure}{\Roman{figure}} \renewcommand{\thesubfigure}{\arabic{subfigure}} \begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Arabic numerals}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Arabic numerals}\label{fig:1b} \end{subfigure} \caption{Capital Roman numerals}\label{fig:1} \end{figure}
The above produces Arabic numerals for the subfigure captions and upper case Roman numerals for the figure caption:
If your document has chapters, then the caption labels would be something like 1.1, 1.2, 2.1, etc. You can customize the numbering or lettering style in these cases. For example:
% This applies if you have chapters \renewcommand{\thefigure}{\thechapter.\Alph{figure}} % set caption label style to 1.A \renewcommand{\thesubfigure}{\arabic{subfigure}} \begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Arabic numerals}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Arabic numerals}\label{fig:1b} \end{subfigure} \caption{Chapter number dot figure letter}\label{fig:1} \end{figure}
This code would produce:
The output differs from a standard caption in that the figure label is now a capital letter rather than a number. The subcaptions are also using arabic numerals. You can also change the period to another character if you want.
The \thechapter
command produces the chapter label, just like \thefigure
produces the figure label. By including\thechapter
in the \thefigure
command, you can reference the chapter in the figure label.
If you want to change the style of the chapter labels, you can in fact override the \thechapter
command just as you override the\thefigure
command. Alternatively, if you want to change the style of the chapter labels only for figure labels, you can do this:
\renewcommand{\thefigure}{\Alph{chapter}.\Alph{figure}}
The above examples were all using figures or subfigures, but the same ideas apply for tables and subtables. Just use \thetable
and \thesubtable
instead of \thefigure
and \thesubfigure
and use the table
and subtable
counters instead of figure
and subfigure
.
Caption package options and captionsetup
The \caption package allows many other aspects of the caption to be modified, via either the \captionsetup
command or in the package options. These include the type of label separator (e.g. the colon in “Figure 1: Caption”), the label format (whether the number or letter is shown and whether it is shown in parentheses), the label and caption text font and style, the justification of the captions and many others.
To use these options, you can either set them when you first include the package:
% options apply to all captions \usepackage[OPTIONS]{caption} % applies to all subfigure and subtable captions \usepackage[OPTIONS]{subcaption}
When you specify the options in the \usepackage
command, they apply to all the captions or subcaptions in the document.
Alternatively, you can use the \captionsetup
command within the document so that all subsequent captions have the desired properties:
\captionsetup[FLOAT_TYPE]{OPTIONS}
FLOAT_TYPE can be table, figure, subtable and subfigure and specifies what type of caption that particular \captionsetup
command applies to, so you can set different options for each of the figure, table, subfigure and subtable floats individually.
When you use the \captionsetup
command in your document, all subsequent captions will use the options you specify. Alternatively, you can put the \captionsetup
within a figure, table, subfigure or subtable environment and it will apply only within that environment.
There are several examples that follow which show the types of things that can be configured with the package options or the\captionsetup
command. The examples here are not an exhaustive listing; there are many other things you can do, so it would be worthwhile to read the caption
package documentation.
Caption justification and font
The following example demonstrates \captionsetup
commands that set the caption label font and the caption text font for the figures and subfigures. It also shows how to change the alignment of the subcaptions under the subfigure.
% for figures: caption label is italic, the caption text is bold / italic \captionsetup[figure]{labelfont=it,textfont={bf,it}} % for subfigures: caption label is bold, the caption text normal. % justification is raggedright (i.e. left aligned) % singlelinecheck=off means that the justification setting is used even when the caption is only a single line long. % if singlelinecheck=on, then caption is always centered when the caption is only one line. \captionsetup[subfigure]{labelfont=bf,textfont=normalfont,singlelinecheck=off,justification=raggedright} \begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Caption}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Caption}\label{fig:1b} \end{subfigure} \caption{Main figure caption.}\label{fig:1} \end{figure}
The effect is shown here:
Note that the subcaptions are left aligned under the subfigure, and the font styles have all changed:
The figure caption labels is italic, the caption text is bold and italic. The subfigure label is bold, the text is normal and it is aligned left. As explained in the code block, singlelinecheck
is turned off so that even short, one line captions use the justification
setting. Otherwise, it will always be centered.
You can also set up the above options for all captions and subcaptions by using the appropriate options when you include the caption and subcaption packages:
% will apply to all captions \usepackage[labelfont=it,textfont={bf,it}]{caption} % will apply to all subcaptions \usepackage[labelfont=bf,textfont=normalfont,singlelinecheck=off,justification=raggedright]{subcaption}
Label format and label separator
If you look at the captions, you can see that the subfigure labels are surrounded by parentheses and a colon separates “Figure 1” from the rest of the caption.
Both of these aspects (the label format and the label separator) can be customized by options in the caption
package. The label format controls how the label shows up: whether it is visible at all, appears plainly or enclosed by parentheses. The label separator is simply the character that appears after the label.
This is the format of the \captionsetup
command to set the labelformat
and labelsep
options:
\captionsetup[FLOAT_TYPE]{labelformat=simple, labelsep=colon}
FLOAT_TYPE
can be table, figure, subtable and subfigure. The labelformat
option can be set to:
Label Format | Result |
---|---|
labelformat = empty | No label is shown - i.e. no number or letter |
labelformat = simple | Shows number or letter in caption |
labelformat = parens | Shows number or letter in caption in parentheses - i.e. (1), (A) |
The labelsep
option can be set to:
Label Separator |
---|
labelsep = none |
labelsep = colon |
labelsep = period |
labelsep = space |
labelsep = quad |
labelsep = newline |
Here is an example where the labelformat and labelsep for the figure caption and subfigure caption are changed individually:
% set up labelformat and labelsep for figure \captionsetup[figure]{labelformat=parens, labelsep=newline} % set up labelformat and labelsep for subfigure \captionsetup[subfigure]{labelformat=simple, labelsep=colon} \begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Simple}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{Simple}\label{fig:1b} \end{subfigure} \caption{Parentheses, newline separator.}\label{fig:1} \end{figure}
The above code produces:
The labelformat
of the subfigure captions is set to simple
, which produces only the caption letter without parentheses. Thelabelsep
is colon for subfigure captions and a newline for the figure.
Subfigure and subtable captions with no number or letter
By setting the labelformat
option to “empty” in your \captionsetup
commands or in the \subcaption
package options, you can disable the display of the number or letter label in subfloats. Here is an example that produces subfigures with no caption numbering or lettering:
% no subfigure caption label. \captionsetup[subfigure]{labelformat=empty} \begin{figure} \centering \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{No caption label}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \includegraphics[width=1in]{placeholder} \caption{No caption label}\label{fig:1b} \end{subfigure} \caption{Main figure caption.}\label{fig:1} \end{figure}
The above code produces:
As you can see, there is no bloody A, B, C or D!
The same command applies for subtables, tables and figures (just make the appropriate substitution in the captionsetup
command).
For figures and tables, which appear in the List of Figures or List of Tables, setting the label format to empty will simply prevent the display of the number or letter in the figure or table caption itself. The letter or number will still appear in the List of Figures or List of Tables.
No caption number for figures and tables
You can disable the caption number for figures and tables by using the \caption*
command:
\begin{figure}[tbp] \centering \includegraphics[width=1in]{placeholder} \caption*{Unnumbered figure caption.} \end{figure}
The code will produce this:
The \caption*
command will produce a caption that has no label or number at all and will not appear in the List of Figures.
Set caption position for subfigures and subtables
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. The same applies for subfigures and subtables:
\begin{figure} \centering \begin{subfigure}[t]{1in} \centering \caption{Caption 1}\label{fig:2a} \includegraphics[width=1in]{placeholder} \end{subfigure} \quad \begin{subfigure}[t]{1in} \centering \caption{Caption 2}\label{fig:2b} \includegraphics[width=1in]{placeholder} \end{subfigure} \caption{Main figure caption.}\label{fig:2} \end{figure}
The result is this:
A table and subtable example
This example shows the above techniques with a table that has two subtables:
% set numbering style \renewcommand{\thetable}{\Roman{table}} \renewcommand{\thesubtable}{\arabic{subtable}} % set up labelformat and labelsep for table \captionsetup[table]{labelformat=simple, labelsep=period} % set up labelformat and labelsep for subtable \captionsetup[subtable]{labelformat=simple, labelsep=colon} \begin{table} \centering \begin{subtable}[t]{1in} \centering \begin{tabular}{|l|l|} \hline 100 & 200\\ \hline \end{tabular} \caption{Caption 1}\label{table:1a} \end{subtable} \quad \begin{subtable}[t]{1in} \centering \begin{tabular}{|l|l|} \hline 100 & 200\\ \hline \end{tabular} \caption{Caption 2}\label{table:1b} \end{subtable} \caption{Table caption text}\label{table:1} \end{table}
The output looks like this:
Cross references
You can reference the caption labels in the text by using \ref{LABEL}
, where LABEL is the label you assigned using a \label
command. This will generate the number or letter corresponding to the label. Subcaptions can be referenced with\subref{LABEL}
. To generate “Figure 1(a)”:
Figure \ref{fig:1}(\subref{fig:1a})
Note that the name assigned using the \label
command is arbitrary so you do not have to keep track of whether a figure is Figure 1 or not. I just called them fig:1 and fig:1a to be more clear here.
You can also reference a subfigure directly without splitting it up into ref
and subref
:
\ref{fig:1a})
This, however, will by default generate 1a
. If you want to use 1(a), you will need to use:
% put these at the beginning of your document. \captionsetup[subfigure]{labelformat=simple} \renewcommand\thesubfigure{(\alph{subfigure})} \begin{figure} \centering \begin{subfigure}[t]{1in} \includegraphics[width=1in]{placeholder} \caption{Caption 1}\label{fig:1a} \end{subfigure} \quad \begin{subfigure}[t]{1in} \includegraphics[width=1in]{placeholder} \caption{Caption 2}\label{fig:1b} \end{subfigure} \caption{Main figure caption}\label{fig:1} \end{figure} Figure \ref{fig:1a}
The first \captionsetup[subfigure]{labelformat=simple}
will prevent double parentheses in the figures themselves.
As before, you can replace figure
with table
and subfigure
with subtable
to work with tables and subtables.
Reset the caption counter
If you need to reset the caption counter for figures (so subsequent figures start at 1 again), you can use the following:
\setcounter{figure}{0} % reset figure counter to 0.
You may use table
or the name of any other counter in lieu of figure
to reset the corresponding counter.
Change the caption name
If you want to change the name of the figure or table caption from “Fig.” to “Figure” or “Table” to “Tab.” or anything else you want, you can use \renewcommand
with \figurename
or \tablename
:
\renewcommand{\tablename}{Tbl} \renewcommand{\figurename}{Image}
The above will change all table captions to be called “Tbl [Table Number]” or “Image [Figure Number]”.
One potential issue you may run into is that the various document classes use a command other than \figurename
or\tablename
in the table captions. For example, the thesis
document class will use \figureshortname
or \tableshortname
in the captions instead. In these cases, renew the corresponding command. To find out what the command is, you can look into the.cls
file of your document class. You can look for the specific string (e.g. “Fig.”) and find out what command was defined for it. Then you can override it. You could also just create a new document class based on the original .cls
file.
Discussion
thank you very much for this tutorial.
It helped me a lot.
Best,
Felix
The thing I did not find is how to control the vertical spacing between the images and the subscriptions.
Dmitri
\abovecaptionskip
\belowcaptionskip
For subcaptions (http://tex.stackexchange.com/questions/49448/controlling-the-subcaption-space-in-memoir):
\subfloattopskip
\subfloatbottomskip
etc.
You can set these lengths using \setlength
is there a way to change the caption labelling order from, for instance given 4 images, a - b - c - d, to b - a - d - c??
Thanks
Thank you very much! Organized and professional website :)
I am having a "single figure" plotted which contains 4 smaller figures named and marked as a,b,c and d within it. So the LaTeX part to include this single figure would be,
\begin{figure}
\includegraphics{Figure1.eps}
\caption{figure caption comes here)
\label{figure1}
\end{figure}
So, if I do a ~\ref{figure1}, it will link to the whole single figure Fig. 1, which is fine.
Now, I want to have,
~\ref{figure1}a or ~\ref{figure1}b appearing as Fig. 1a or Fig. 1b with the same colour & hence the link (redirection to Fig. 1 caption). At present a or b is getting included, which is my concern.
Will you be able to suggest me an answer for this.?
thanking you
regards
arun
I had the problem to change the caption name,
but in the end
\addto\captionsngerman{\renewcommand\figurename{Bild}}
was to my rescue. Just wanted to post that in case someone
has the same issue.
regards Chris
Thanks for pointing this out.
http://www.peteryu.ca/tutorials/publishing/pdf_manipulation_tips#autocrop_pdf_white_space
In \documentclass{article}
If I enter
"
\begin{figure}
\centering
\includegraphics[width=6.0in]{initial_profile.pdf}
\textbf{\caption{\textmd{\small{Profiles initial sounding.}}}}
\label{initial}
\end{figure}
Figure~\ref{initial} shows... "
The Caption under the figure shows "Figure 1." (which is fine) but in the text it is referred to as "Figure 1.1 shows...".
How would you change this to "Figure 1 shows ..."
\textbf{\caption{\textmd{\small{Profiles initial sounding.}}}\label{initial}}
When I tried exactly what you had, I didn't get Figure 1.1 but rather an undefined reference. I hope that fixes it.
I also wasn't able to see the effect of \textbf in the caption.
I have a figure which has several subfigures that some of them should appear on the next page. Is there a way of doing that? At the moment I am putting the additional figures in another figure with no caption but this is not nice because I want to continue the subcaptions from the previous figure!
Thanks in advance,
Nehzat
Nehzat
\usepackage[figurename=Fig.]{caption}
Michael A-D
I am using IEEEtran. I can't figure out a way to do that. Kindly help.
Thank you very much for the clear answers to solve the changing in Table in listoftables , thank's to you I succeeded to have Table A Table B and next
arabic Table 1 and Table 2 (etc).
The "cerise on the pye " should be how to correc:
A Topbase quantum defects for 52 F e26 and ions . . . . . . . . . . . . . . . . . . . . 4
B Topbase quantum defects for 24 M g12 and ions . . . . . . . . . . . . . . . . . . . . 5
1 < rα > integrated Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 18
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 19
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 20
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 21
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 22
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 23
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 24
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 25
2 < rα > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 26
3 < rα > values l=1 P integrated with Mathematica . . . . . . . . . . . . . . . . . . 28
4 < rα > l=1 P states values Messiah formulae . . . . . . . . . . . . . . . . . . . . . 38
4 < rα > l=1 P states values Messiah formulae . . . . . . . . . . . . . . . . . . . . . 39
4 < rα > l=1 P states values Messiah formulae . . . . . . . . . . . . . . . . . . . . . 40
Have you any idea to suppress the "repetition" of the caption, in using :
longtable with Contd pages?
Thank's a lot
Amaury
You may have to change caption for subsequent pages (the one that occurs before \endhead) to \caption* or \caption[] if you don't want it to appear in the list but I haven't tested this yet.
Many thanks for the quick answer to my question!
Your instructions worked perfectly.
See there:
List of Tables
A Topbase quantum defects for 52Fe26 and ions . . . . . . . . . . . . . . . . . . . . 4
B Topbase quantum defects for 24Mg12 and ions . . . . . . . . . . . . . . . . . . . . 5
1 < r > integrated Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 < r > values using extending the Messiah formulae. . . . . . . . . . . . . . . . . 18
3 < r > values l=1 P integrated with Mathematica . . . . . . . . . . . . . . . . . . 28
4 < r > l=1 P states values Messiah formulae . . . . . . . . . . . . . . . . . . . . . 38
4
I was looking for a way to have "Figure 1 - caption" so I used the below command, since I didn't see anything similar in your post (correct me if I'm wrong)
\usepackage{caption}
\renewcommand{\thefigure}{\arabic{figure}}
\DeclareCaptionLabelFormat{dash}{#1 #2 -- }
\captionsetup[figure]{labelformat=dash}