There is a problem with referencing subfigures.
When I add the line containing \caption{}
, everything works perfect, but caption of a figure must be below the figure.
How can I solve this problem?
Here is the code:
\documentclass{article}
\usepackage{subcaption}
\begin{document}
\renewcommand{\thesubfigure}{(\alph{subfigure})}
\begin{figure}
\caption{} % When I add this line, everything works perfect, but caption of a figure must be below the figure.
\begin{minipage}[b]{0.50\textwidth}
1A
\captionof{subfigure}{1A}
\label{fig:1:A}
\end{minipage}
\begin{minipage}[b]{0.50\textwidth}
1B
\captionof{subfigure}{1B}
\label{fig:1:B}
\end{minipage}
\caption{First~\ref{fig:1:A}~\ref{fig:1:B}}
\end{figure}
\begin{figure}
\begin{minipage}[b]{0.50\textwidth}
2A
\captionof{subfigure}{2A}
\label{fig:2:A}
\end{minipage}
\begin{minipage}[b]{0.50\textwidth}
2B
\captionof{subfigure}{2B}
\label{fig:2:B}
\end{minipage}
\caption{First~\ref{fig:2:A}~\ref{fig:2:B}}
\end{figure}
\end{document}
Note 1: The real document has 3500 lines so I can not set the value of the figure counter manually via \renewcommand\thefigure{2}
.
Note 2: In a single figure of the real document, there are plenty of minipage
s that contain tikz pictures so I prefer using minipage.
Best Answer
The cubcaption manual hints to use the command
subcaption
instead of captionof. It increases the counters internally. Another possibility would be to use the provided environmentsubfigure
(it uses a minipage itself and got the same syntax, you could just do a string replace) along with the caption command we all know.Both of the following MWEs produce the same end result.
Using subfigure: