texblog

Sub-caption above subfigures and subtables

I was recently asked an interesting question about how to place a sub-caption on top of a sub-figure. By default, sub-captions are produced below sub-figures.

When using the subfigure package, the answer is reasonably easy. The package has an option to move the sub-captions on top of the figure.

\usepackage[FIGTOPCAP]{subfigure}

However, I was curious how other packages solve the problem, specifically subfig and subcaption.

Below are the solutions for all three sub-figure packages as well as the sub-tables.

 

Subfigure

We have already seen that subfigure solves the problem through a package option, which has to be typed in capital letters.

\usepackage[FIGTOPCAP]{subfigure}

\documentclass[11pt]{article}
\usepackage[FIGTOPCAP]{subfigure}
\begin{document}

\begin{figure}[ht]
\centering
\subfigure[Caption of subfigure 1]{
    \rule{4cm}{3cm}
    \label{fig:subfig1}
}
\subfigure[Caption of subfigure 2]{
    \rule{4cm}{3cm}
    \label{fig:subfig2}
}
\subfigure[Caption of subfigure 3]{
    \rule{4cm}{3cm}
    \label{fig:subfig3}
}
\caption[Optional caption for list of figures]{Main caption for subfigures \subref{fig:subfig1}, \subref{fig:subfig2} and \subref{fig:subfig3}}
\label{fig:subfigureExample}
\end{figure}

\end{document}

 

Subfig

Similar to subfigure, the subfig package also changes the caption position through a package option.

\usepackage[position=top]{subfig}

Alternatively, the caption position can be controlled through the captionsetup command.

\captionsetup{position=top}

This has the advantage that it can be placed anywhere within the document and similarly reset to the default.

\captionsetup{position=bottom}

\documentclass[11pt]{article}
\usepackage[position=top]{subfig}
\begin{document}
\begin{figure}[ht]
\centering
\subfloat[short for lof][Caption for sub-figure 1]{
    \rule{4cm}{3cm}
    \label{fig:subfig1}
}
\subfloat[short for lof][Caption for sub-figure 2]{
    \rule{4cm}{3cm}
    \label{fig:subfig2}
}

\subfloat[short for lof][Caption for sub-figure 3]{
    \rule{4cm}{3cm}
    \label{fig:subfig3}
}
\caption[Optional caption for list of figures]{Main caption for subfigures \subref{fig:subfig1}, \subref{fig:subfig2} and \subref{fig:subfig3}}
\label{fig:subfigureExample}
\end{figure}
\end{document}

 

Subcaption

The subcaption package handles positioning differently from subfigure and subfig. It defines the subfigure environment which is simply a minipage. Figures are then placed within the environment along with the caption and label. The caption can therefore be move on top of the figure simply by rearranging the commands.

\begin{subfigure}[b]{0.45\textwidth}
	% Caption before figure
	\subcaption[short for lof]{Caption for sub-figure}
	\includegraphics[width=\linewidth]{figure-file}
	\label{fig:subfig}
\end{subfigure}

\documentclass[11pt]{article}
\usepackage{subcaption}
 \begin{document}
\begin{figure}
	\centering
	\begin{subfigure}[b]{0.45\textwidth}
		\subcaption[short for lof]{Caption for sub-figure 1}
		\rule{\linewidth}{3cm}
		\label{fig:subfig1}
	\end{subfigure}%
	\quad
	\begin{subfigure}[b]{0.45\textwidth}
		\subcaption[short for lof]{Caption for sub-figure 2}
		\rule{\linewidth}{3cm}
		\label{fig:subfig2}
	\end{subfigure}

	\begin{subfigure}[b]{0.45\textwidth}
		\subcaption[short for lof]{Caption for sub-figure 3}
		\rule{\linewidth}{3cm}
		\label{fig:subfig3}
	\end{subfigure}
	\caption[Optional caption for list of figures]{Main caption for subfigures \subref{fig:subfig1}, \subref{fig:subfig2} and \subref{fig:subfig3}}
\end{figure}
\end{document}

 

Table

Similar solutions exist for placement of sub-table captions above or below the table.

% Subfigure package
\usepackage[TABTOPCAP]{subfigure} % above
\usepackage[TABBOTCAP]{subfigure} % below (default)

% Subfig package
\usepackage{subfig}
\captionsetup[subtable]{position=top}

% Subcaption package
\begin{subtable}[b]{0.45\textwidth}
	% Caption before figure
	\subcaption[short for lof]{Caption for sub-table}
	...
	\label{tab:subtab}
\end{subtable}
Exit mobile version