3

I use bellow code for make subfig in my text but figure caption are 2.2a, but I want 2.2(a). how change my code? note: I don't want change all off code please correct my code.

\documentclass{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\usepackage{subfig}

\begin{document}
\section{subfig}
\subsection{problem}
\begin{figure}[!ht]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{t.jpg}
          \caption{this fig}
           \setlength\abovecaptionskip{0pt}
            \label{f4}
    \end{subfigure}

     \vspace{0cm}
    \begin{subfigure}[b]{0.5\textwidth}
            \includegraphics[width=\textwidth]{t.jpg}
             \caption{this fig}
               \setlength\abovecaptionskip{0pt}
            \label{f5}
    \end{subfigure}

\caption{this fig}
   \label{f3}
\end{figure}
in fig.\ref{f5}
\end{document}
1
  • Choose between either subcaption or subfig, but not both. I'd suggest the former, since you're already using caption (from the same author).
    – Werner
    Commented Nov 23, 2014 at 7:15

1 Answer 1

2

I assume that you want 1(b) when you do \ref{f5}. For that change:

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

Your code modified

\documentclass{book}
\usepackage{caption}
\usepackage[labelformat=simple]{subcaption}
\usepackage[demo]{graphicx}
\renewcommand\thesubfigure{(\alph{subfigure})}
\begin{document}
\chapter{One}
\section{subfig}
\subsection{problem}
\begin{figure}[!ht]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
      \includegraphics[width=\textwidth]{t.jpg}
          \caption{this fig}
           \setlength\abovecaptionskip{0pt}
            \label{f4}
    \end{subfigure}

     \vspace{0cm}
    \begin{subfigure}[b]{0.5\textwidth}
            \includegraphics[width=\textwidth]{t.jpg}
             \caption{this fig}
               \setlength\abovecaptionskip{0pt}
            \label{f5}
    \end{subfigure}

\caption{this fig}
   \label{f3}
\end{figure}
in \ref{f5}
\end{document}

enter image description here

0

You must log in to answer this question.

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