4

I would like to put three pictures with sub-captions in two rows using the subfig package. I want to center the single picture in the second row. I use the following code :

\documentclass[12pt,leqno]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{lmodern} 
\usepackage{graphicx}                 
\usepackage{float}
\usepackage{keyval,caption,subfig}
\captionsetup[subfigure]{%format=hang, singlelinecheck=false, font={tt,bf,sc}}
\newsubfloat[position=top,listofformat=subsimple]{figure}

\parindent 1cm
\parskip 0.2cm
\topmargin 0.2cm
\oddsidemargin 1cm
\evensidemargin 0.5cm
\textwidth 15cm
\textheight 21cm

\DeclareGraphicsExtensions{.png}

\begin{document}

\begin{figure}[H]%
\centering
\subfloat[First subtitle]{
\begin{picture}(226,139)
{\includegraphics{abra_1_a}}
\end{picture}
}
\qquad
\subfloat[Second subtitle]{
\begin{picture}(226,139)
{\includegraphics{abra_1_b}}
\end{picture}
}\\
\subfloat[Third subtitle]{
\begin{picture}(226,139)
{\includegraphics{abra_1_c}}
\end{picture}
}%
\caption{Assignment}
\end{figure}

\end{document}    

Result : The pictures appear in three rows.

Question : What is wrong in my code ?

5

Why do you use the picture environment? The following does what you require:

\documentclass[12pt,leqno]{book}
\usepackage[demo]{graphicx}                 
\usepackage{float}
\usepackage{subfig}

\begin{document}

\begin{figure}[H]%
\centering
\subfloat[First subtitle]{\includegraphics{abra_1_a}}\hfill%
\subfloat[Second subtitle]{\includegraphics{abra_1_b}}\\
\subfloat[Third subtitle]{\includegraphics{abra_1_c}}
\caption{Assignment}
\end{figure}

\end{document}

enter image description here

Using the optional argument of \includegraphics you can change the figure attributes, e.g.,

\includegraphics[width=.3\linewidth]{abra_1_a}

I used the demo option for graphicx to make my example compilable for everyone; do not use that option in your actual document.

1

There is no need for the picture environment. Use the width option

\documentclass[12pt,leqno]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{lmodern} 
\usepackage[demo]{graphicx}% DELETE [DEMO] after trying
\usepackage{keyval,caption,subfig}
\captionsetup[subfigure]{format=hang, singlelinecheck=false, font={tt,bf,sc}}

\begin{document}
\begin{figure}
\centering
\subfloat[First subtitle]{\includegraphics[width=0.49\textwidth]{abra_1_a}}
\hfill
\subfloat[Second subtitle]{\includegraphics[width=0.49\textwidth]{abra_1_b}}

\subfloat[Third subtitle]{\includegraphics{abra_1_c}}

\caption{Assignment}
\end{figure}

\end{document}   

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.