我想放置两个图形,每个图形figure
都有相邻的子图形。我尝试使用minipage
,但 tex 不喜欢\subfigure
。Not in outer par mode
有没有办法将带有子图形的图形彼此相邻放置?
\begin{figure*}[htbp]
\begin{minipage}[hbt]{0,49\textwidth}
\begin{figure}
\subfigure[Subfigure 1.1]{
\label{fig:subfig1_1}
\includegraphics[scale=0.42]{graphs/sub_1_1.pdf}
}
\subfigure[Sub 1.2] {
\label{fig:subfig1_2}
\includegraphics[scale=0.42]{graphs/sub_1_2.pdf}
}
}
\label{fig:subfigure1}
\caption{Subfigure 1}
\end{figure}
\end{minipage}
\begin{minipage}[hbt]{0,49\textwidth}
%... as above
\end{minipage}
\end{figure*}
答案1
您不能将浮动对象放在 内minipage
,但可以将minipage
s 放在浮动对象内。我注意到您正在使用过时的subfigure
包;您应该改用subfig
或subcaption
。
下面有两种方法;第一种方法是使用subfig
包,另一个使用subcaption
包裹:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.
\begin{document}
\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}
\end{document}
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}
\end{document}
选项demo
只是graphicx
用黑色矩形替换实际图形;不是在实际文档中使用该选项。
答案2
由于figure
是浮动对象而minipage
s 不是,因此不能在 sfigure
内使用 s minipage
。一种方法是避免使用figure
,而使用captionof
from caption
/ subcation
(或capt-of
)包。
代码:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\noindent
\begin{minipage}[t]{0.49\linewidth}%
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\textwidth]{example-image-a}%
\captionof{subfigure}{sub figure - 1}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\linewidth]{example-image-b}
\captionof{subfigure}{sub figure - 2}
\end{minipage}
\captionof{figure}{figure one}
\end{minipage}%
\setcounter{subfigure}{0}
\hfill
\begin{minipage}[t]{0.49\linewidth}%
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\textwidth]{example-image-c}%
\captionof{subfigure}{sub figure - 1}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\linewidth]{example-image}
\captionof{subfigure}{sub figure - 2}
\end{minipage}
\captionof{figure}{figure two}
\end{minipage}%
\end{document}