我有两个垂直对齐的子图,如下所示,并且运行良好:
\begin{figure}[h]
\centering
\subfigure[a]{
\includegraphics[width=0.8\textwidth]{image1}}\\
\subfigure[b]{
\includegraphics[width=1\textwidth]{image2}}
\caption{caption1}
\label{lable1}
\end{figure}
但是,当我尝试使用\fbox
或\frame
新行命令为它们两者添加边框时\\
,会返回错误!如果我将其删除,则不会出现错误,但子图不再垂直对齐。
如何才能同时让图形垂直对齐并且让它们周围都有边框?
答案1
这里有两种不同的方法来处理\\
,\fbox
具体取决于您是否知道所需的宽度。实际上,使用 tabular 您甚至不需要\fbox
。
\documentclass{article}
\usepackage[tight,footnotesize]{subfigure}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\hfil\fbox{\begin{minipage}{\dimexpr \textwidth-2\fboxsep-2\fboxrule}% maximum allowed
\centering
\subfigure[a]{%
\includegraphics[width=0.8\textwidth]{example-image-a}}\\
\subfigure[b]{%
\includegraphics[width=0.9\textwidth]{example-image-b}}
\end{minipage}}
\caption{caption1}
\label{lable1}
\end{figure}
\begin{figure}
\hfil\begin{tabular}{|c|}% width unknown
\hline
\subfigure[a]{%
\includegraphics[width=0.8\textwidth]{example-image-a}}\\
\subfigure[b]{%
\includegraphics[width=0.9\textwidth]{example-image-b}}\\
\hline
\end{tabular}
\caption{caption2}
\label{lable2}
\end{figure}
\end{document}
答案2
一个非常简单的环境解决方案framed
:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{framed}
\begin{document}
\begin{figure}[htb]
\begin{framed}
\centering
\begin{subfigure}{0.65\linewidth}
\includegraphics[width=\linewidth]{ernst_vierge}
\caption{}
\end{subfigure}
\vskip 4ex
\begin{subfigure}{\linewidth-2\fboxsep-2\fboxrule}
\includegraphics[width=\linewidth]{Piero_di_Cosimo_1}
\caption{}
\end{subfigure}
\end{framed}
\caption{caption1}
\label{lable1}
\end{figure}
\end{document}
答案3
还有一个选择:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{calc}
\begin{document}
\begin{figure}[htb]
\fbox{\begin{minipage}{\textwidth-2\fboxsep-2\fboxrule}
\centering
\begin{subfigure}{0.8\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{}
\end{subfigure}
\begin{subfigure}{\linewidth-2\fboxsep-2\fboxrule}
\includegraphics[width=\linewidth]{example-image-b}
\caption{}
\end{subfigure}
\end{minipage}}
\caption{caption1}
\label{lable1}
\end{figure}
\end{document}
软件包subfigure
已过时并被 取代subfig
。不过,我建议使用更高级的subcaption
及其环境subfigure
。
答案4
tcolorbox
缺少以下解决方案:
\documentclass{article}
\usepackage[tight,footnotesize]{subfigure}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{figure}
\begin{tcolorbox}
\centering
\subfigure[a]{%
\includegraphics[width=0.8\textwidth]{example-image-a}}\\
\subfigure[b]{%
\includegraphics[width=0.9\textwidth]{example-image-b}}
\end{tcolorbox}
\caption{caption1}
\label{lable1}
\end{figure}
\end{document}