我想使用该subfig
包将三张带子标题的图片放在两行中。我想将单张图片放在第二行的中央。我使用以下代码:
\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}
结果 :图片分为三行。
问题 :我的代码有什么错误?
答案1
为什么要使用picture
环境?以下内容可满足您的要求:
\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}
使用可选参数\includegraphics
可以更改图形属性,例如,
\includegraphics[width=.3\linewidth]{abra_1_a}
我使用了demo
选项来graphicx
使我的例子可供所有人编译;不是在实际文档中使用该选项。
答案2
不需要环境picture
。使用 width 选项
\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}