2

I would like to reference a subfigure as "Fig. 3 (a)" using \ref{fig:figure3a} but instead I am getting "Fig. 3a". How would I add the braces to a subfigure reference?

Where the original image beng referenced is two subfigures as shown below.

\documentclass[12pt,oneside,openany,a4paper,afrikaans,english,masters-t,goldenblock]{usthesis}

%% Language and font encodings
\usepackage[afrikaans, english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}

%%%%%%%%%%%%%%%%%%%%%%% Packages %%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{svg} % To be able to add SVG images
\usepackage{usbib}
\bibliographystyle{unsrt}
\setcitestyle{square}
\bibpunct{[}{]}{,}{n}{,}{,}
\usepackage{caption}
\usepackage{subcaption}

%%%%%%%%%%%%%%%%%%%%%%% Sets page size and margins %%%%%%%%%%%%%%%%%%%%%%%
\usepackage{geometry}
\geometry{a4paper,  total={210.2mm,297.3mm}, left=25mm, right = 25mm, top=26.3mm, bottom=43.8mm }

\begin{document}

In text reference to fix: Fig.~\ref{fig:figure3a}.

\begin{figure}
\centering

  \begin{subfigure}[hbt]{0.31\textwidth}
    \includesvg[scale=0.31]{images/image1a}
    \caption{image a}
    \label{fig:figure3a}
  \end{subfigure} \hfill

  \begin{subfigure}[hbt]{0.31\textwidth}
    \includesvg[scale=0.31]{images/image1b}
    \caption{image b}
    \label{fig:figure3b}
  \end{subfigure}  \hfill

\caption{outer caption.}
\label{fig:figure3}
\end{figure}

\bibliography{sample} % no need for bibliography

\end{document}

I tried using:

%%% Fig. 1(a) instead of Fig. 1a
\usepackage[caption=false,labelformat=simple]{subfig} % "labelformat=simple" removes the parenthesis from the caption label
\renewcommand\thesubfigure{(\alph{subfigure})}  % This one adds parenthesis to the display format
%%

from here (a stack overflow post on the problem using subfig package) but I got an error message, even when I tried to remove the subcaption package.

I want to keep the packages above and get the reference to work.

1 Answer 1

4

Replace

\usepackage{subcaption}

by

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}

The second line adds parentheses whenever referencing the value of the counter. This will lead to double parentheses in the sub-captions, as there the parentheses are the default. Hence the option labelformat=simple to remove them.

1
  • Thank you @gernot , this worked well.
    – user4933
    Commented Jan 1, 2022 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .