8

I have a figure with 3 subfigures. I used the \ref{fig:2} in my text and I got 2a. Can anyone knows how to make it 2(a) instead of 2a?

Below is an example of my code:

\begin{document}

\begin{figure}

\centering

\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{graph1.jpg}
    \caption{$y=x$}
    \label{fig:1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{graph2.jpg}
    \caption{$y=sinx$}
    \label{fig:2}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{graph3.jpg}
    \caption{$y=cosx$}
    \label{fig:3}
\end{subfigure}
\caption{Three simple graphs}
\label{fig:three graphs}
\end{figure}

\end{document}

With Thanks

Sigur
  • 37,330
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jan 02 '15 at 11:13
  • Does http://tex.stackexchange.com/questions/87595/change-format-of-reference-to-a-subfigure help? – egreg Jan 02 '15 at 12:17
  • Possibly \renewcommand{\thesubfigure}{(\alph{subfigure})} and \captionsetup[sub]{labelformat=simple} are sufficient. – egreg Jan 02 '15 at 12:31

1 Answers1

8

You can just do

\renewcommand{\thesubfigure}{(\alph{subfigure})}
\captionsetup[sub]{labelformat=simple}

Here's a complete example; notice that \hfill should go next to \end{subfigure} and that sinx should be \sin x (similarly for \cos x).

\documentclass[a4paper]{article}
\usepackage{caption,subcaption,graphicx}

\renewcommand\thesubfigure{(\alph{subfigure})}
\captionsetup[sub]{
  labelformat=simple
}

\begin{document}
\begin{figure}

\centering

\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{$y=x$}
    \label{fig:1}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{$y=\sin x$}
    \label{fig:2}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{$y=\cos x$}
    \label{fig:3}
\end{subfigure}
\caption{Three simple graphs}
\label{fig:three-graphs}
\end{figure}

Here are the references: \ref{fig:1}, \ref{fig:2}, \ref{fig:3}
which are subfigures to figure~\ref{fig:three-graphs}.

\end{document}

See Change format of reference to a subfigure for other customizations.

enter image description here

egreg
  • 1,121,712