latexsubcaption

How to call a subfigure in overleaf?


I want to call \ref for a subfigure, but it does not work as expected. How do we fix the problem?

Here are my codes in overleaf:

\usepackage{subcaption}
\usepackage{graphix}

\begin{document}


The numerical results are shown in \ref{smpc_and_mpc}.
\begin{figure}[ht]
\centering
\begin{subfigure}{\textwidth}
   \centering
    \includegraphics[width=0.95\textwidth]{Gambar/mpc_FPA.eps}`
    \caption{MPC`}
   \\label{subfig:mpc}`
\end{subfigure}
\begin{subfigure}{\textwidth}
   \centering 
   \includegraphics[width=0.95\textwidth]{Gambar/SMPC.eps}
   \caption{SMPC}
   \label{subfig:smpc}
\end{subfigure}
\caption{Flight path angle responses tested using 200 different parameters with 20\% deviation about nominal values of $a_{13}$ and $a_{23}$}
\label{smpc_and_mpc}
\end{figure}

\ref{subfig:mpc} and \ref{subfig:smpc} compare the flight path angle responses of MPC and SMPC, using parameters from \ref{tabel_SMPC}.

\end{document}

`

The output that we expect is

Figure 1(a) and Figure 1(b) compare the flight path angle responses of MPC and SMPC, using parameters from Table 1.

However, it cannot work properly. The output is as follows:

Figure 1a and Figure 1b compare the flight path angle responses of MPC and SMPC, using parameters from Table 1.


Solution

  • As shown on page 12 of the subcaption documentation, you can redefine \thesubfigure like this:

    \documentclass{article}
    \usepackage{graphicx}
    
    \usepackage[labelformat=simple]{subcaption}
    \renewcommand\thesubfigure{(\alph{subfigure})}
    
    \begin{document}
    
    
    The numerical results are shown in \ref{smpc_and_mpc}.
    \begin{figure}[ht]
    \centering
    \begin{subfigure}{\textwidth}
       \centering
        \includegraphics[width=0.5\textwidth]{example-image-duck}
        \caption{MPC}
       \label{subfig:mpc}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
       \centering 
       \includegraphics[width=0.5\textwidth]{example-image-duck}
       \caption{SMPC}
       \label{subfig:smpc}
    \end{subfigure}
    \caption{Flight path angle responses tested using 200 different parameters with 20\% deviation about nominal values of $a_{13}$ and $a_{23}$}
    \label{smpc_and_mpc}
    \end{figure}
    
    \ref{subfig:mpc} and \ref{subfig:smpc} compare the flight path angle responses of MPC and SMPC, using parameters from \ref{smpc_and_mpc}.
    
    \end{document}
    

    enter image description here