# Why latex doesn't recognize my subfigures?

\documentclass[11pt,a4paper,twoside]{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx} % [demo] is just for the example

\begin{document}

\begin{figure}[ht]
\centering
\subfloat[A bounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3a.jpg}\label{fig:subfig5}}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3b.jpg}\label{fig:subfig6}}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3c.jpg}\label{fig:subfig7}}
\caption[Optional caption for list of figures 5-8]{Feasible region}
\label{fig:subfigureExample2}
\end{figure}

Reference to figure \ref{fig:subfigureExample2} and \ref{fig:subfig6}.

\end{document}


This code works for me using the subfig package.

\documentclass[11pt,a4paper,twoside]{book}
\usepackage{caption}
\usepackage{subfig}
\usepackage[demo]{graphicx} % [demo] is just for the example

\begin{document}

\begin{figure}[ht]
\centering
\subfloat[A bounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3a.jpg}\label{fig:subfig5}}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3b.jpg}\label{fig:subfig6}}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3c.jpg}\label{fig:subfig7}}
\caption[Optional caption for list of figures 5-8]{Feasible region}
\label{fig:subfigureExample2}
\end{figure}

Reference to figure \ref{fig:subfigureExample2} and \ref{fig:subfig6}.

\end{document}


For subcaption you need a different syntax

\documentclass[11pt,a4paper,twoside]{book}
%\usepackage{caption}
\usepackage{subcaption}
\usepackage[demo]{graphicx} % [demo] is just for the example
\begin{document}

\begin{figure}
\centering
\begin{subfigure}{0.3\textwidth}\Huge A\caption{A bounded feasible region}\label{fig:subfig5}\end{subfigure}
\begin{subfigure}{0.3\textwidth}\Huge B\caption{A bounded feasible region}\label{fig:subfig6}\end{subfigure}
\begin{subfigure}{0.3\textwidth}\Huge C\caption{A bounded feasible region}\label{fig:subfig7}\end{subfigure}
\caption[Optional caption for list of figures 5-8]{Feasible region}
\label{fig:subfigureExample2}
\end{figure}

Reference to figure: \ref{fig:subfigureExample2} and \ref{fig:subfig6}.

\end{document}


In addition to loading the subfig package instead of the subcaption package, you should also provide some code to provide whitespace between the three items in the figure. I suggest you drop the \centering instruction and insert \hspace{\fill} in two places.

\documentclass[11pt,a4paper,twoside]{book}
%\usepackage{caption}   %% not needed for this MWE
\usepackage{subfig}
\usepackage[demo]{graphicx} % [demo] is just for the example
\begin{document}

\begin{figure}[ht]
\subfloat[A bounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3a.jpg}\label{fig:subfig5}}
\hspace{\fill}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3b.jpg}\label{fig:subfig6}}
\hspace{\fill}
\subfloat[Unbounded feasible region]{\includegraphics[width=0.3\textwidth, keepaspectratio]{2s3c.jpg}\label{fig:subfig7}}

\caption[Optional caption for list of figures 5--8]{Feasible region}
\label{fig:subfigureExample2}
\end{figure}

Reference to figure \ref{fig:subfigureExample2} and \ref{fig:subfig6}.
\end{document}

• Why doesn't the latex runs when I use caption package? I am typing a book and I used the sub caption and caption package earlier. If I remove them now will it effect other contents of my book? – Agog Sep 20 '14 at 16:15
• @Agog - Please provide more information about the problem you're experiencing. I had commented out the instruction \usepackage{caption} from the code purely because it wasn't required for the MWE (minimal working example). If I do load the caption package in the MWE, nothing bad happens. Do you maybe load the caption package with some special options, or enable the options via a \captionsetup directive? Please advise. – Mico Sep 20 '14 at 16:40
• Thanks for making things clear to me!! I went through my codes again and found typographical error. It has nothing to do with \usepackage{caption}. – Agog Sep 20 '14 at 18:05
• @Agog - Glad I was able to help. – Mico Sep 20 '14 at 18:21