3
\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}

The pdf which forms is shown below

3 Answers 3

7

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}

enter image description here

0
5

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}
4

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.

enter image description here

\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}
4
  • 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
    Commented Sep 20, 2014 at 16:15
  • 1
    @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
    Commented Sep 20, 2014 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
    Commented Sep 20, 2014 at 18:05
  • @Agog - Glad I was able to help.
    – Mico
    Commented Sep 20, 2014 at 18:21

You must log in to answer this question.

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