1

I want to have the captions of my subfigures showing not only the current subfigure counter, but also the current figure number. So, for example, subfigure 1a would have caption 1.a - Caption. I managed to do that by changing the \thesubfigure command, but then I ran into two problems (MWE follows):

  1. If I put the figure caption below the figures (which I want to do), the figure counter is not yet updated when the subfigure captions are compiled. Changing the counter manually does not work, because in that case the Figure caption will have the wrong number. (And I don't want to change it twice every time)

  2. When I reference a subfigure, the figure counter is repeated twice.

Regarding the second issue, I found this question and I imagine I could change something like the \p@subfigure to show only \thesubfigure, but that would give me a reference \thefigure.\thesubfigure, while I would like to reference the subfigures as 1a instead of 1.a.

About the first issue, the closest I could find to a solution was this question, but I don't want to add every number manually, as I have many figures like this in my document. I know this has to do with what is explained here, but if I put the figure \caption before the subfigures, the caption position moves to the top.

As an extra, any tips on how to change the labelsep of subfigures caption to - would be appreciated.

INFO: The way I'm adding the subfigure captions to each tikzpicture was inspired by this question.

\documentclass{article}
\usepackage{fullpage}
\usepackage{amsbsy, amscd, amsfonts, amssymb, amstext, amsmath, mathtools, amsthm} 
\usepackage{float, tikz, hyperref}
\usepackage{caption, subcaption}

\renewcommand{\thesubfigure}{\thefigure.\alph{subfigure}}
\captionsetup[subfigure]{labelfont=bf,labelformat=simple, labelsep=space}

\begin{document}

\begin{figure}[H]
\centering
 \begin{tikzpicture}
      \shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
      \draw (0,0) circle (2cm);
      \node (c) at (-90:2) {};
      \node[text width=6cm,align=center,anchor=north] at ([yshift=-5mm]c.south) {\captionof{subfigure}{Sphere \label{subfig1}}};
 \end{tikzpicture}
%
 \begin{tikzpicture}
        \draw[black!80,thick,dashed] (2,2) circle (2cm);
        \begin{scope}[shift={(2,2)}]
            \node (c) at (-90:2) {};
        \end{scope}    
        \node[text width=6cm,align=center,anchor=north] at ([yshift=-5mm]c.south) {\captionof{subfigure}{Above view \label{subfig2}}};
 \end{tikzpicture}
\caption{A sphere in $\mathbb{R}^3$}
\label{fig}
\end{figure}

Reference: \ref{subfig1} . It should show 1a.

\end{document}
1
  1. The example document does not compile on my computer because of the \captionof{subfigure}. So I changed them to \subcaption. (According to https://tex.stackexchange.com/a/310400/205700 \captionof{subfigure} is incorrect. I guess that's why you have trouble with the figure counter for the sub-captions.)
  2. If the dot should only appear in the captions, but not in the references, one need to define an extra caption label format, e.g.:
\DeclareCaptionLabelFormat{subfigure}{\thefigure.#2}
\captionsetup[subfigure]{labelformat=subfigure}

This leaves the numbering scheme, references etc. intact and only changes the appearance of the sub-captions in the figures.

The complete document, including the two changes above:

\documentclass{article}
\usepackage{fullpage}
\usepackage{amsbsy, amscd, amsfonts, amssymb, amstext, amsmath, mathtools, amsthm}
\usepackage{float, tikz, hyperref}
\usepackage{caption, subcaption}

\DeclareCaptionLabelFormat{subfigure}{\thefigure.#2}
\captionsetup[subfigure]{labelfont=bf,labelformat=subfigure,labelsep=space}

\begin{document}

\begin{figure}[H]
\centering
 \begin{tikzpicture}
      \shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
      \draw (0,0) circle (2cm);
      \node (c) at (-90:2) {};
      \node[text width=6cm,align=center,anchor=north] at ([yshift=-5mm]c.south) {\subcaption{Sphere \label{subfig1}}};
 \end{tikzpicture}
%
 \begin{tikzpicture}
        \draw[black!80,thick,dashed] (2,2) circle (2cm);
        \begin{scope}[shift={(2,2)}]
            \node (c) at (-90:2) {};
        \end{scope}
        \node[text width=6cm,align=center,anchor=north] at ([yshift=-5mm]c.south) {\subcaption{Above view \label{subfig2}}};
 \end{tikzpicture}
\caption{A sphere in $\mathbb{R}^3$}
\label{fig}
\end{figure}

Reference: \ref{subfig1} . It should show 1a.

\end{document}
| improve this answer | |
1

With use of the subcaption (which you already loaded):

\documentclass{article}
\usepackage{fullpage}
\usepackage{amssymb, mathtools}
\usepackage{caption, subcaption}
\usepackage{tikz}

\usepackage{hyperref}

\begin{document}
\section{Test}
\begin{figure}[ht]
\centering
    \begin{subfigure}{0.45\linewidth}
    \centering
 \begin{tikzpicture}
      \shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
      \draw (0,0) circle (2cm);
      \node (c) at (-90:2) {};
\end{tikzpicture}
\caption{Sphere}
\label{subfig1}
    \end{subfigure}
    \hfil
    \begin{subfigure}{0.45\linewidth}
    \centering
 \begin{tikzpicture}
        \draw[black!80,thick,dashed] (2,2) circle (2cm);
        \begin{scope}[shift={(2,2)}]
            \node (c) at (-90:2) {};
        \end{scope}
\end{tikzpicture}
    \caption{Above view};
     \label{subfig2}
\end{subfigure}
    \caption{A sphere in $\mathbb{R}^3$}
    \label{fig}
\end{figure}

Reference: \ref{subfig1} . It should show 1a.
\end{document}

Note: package hyperref (with rare exception as is cleveref) had to be load last in preamble.

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.