3

I have two vertically aligned subfigures as follows and it works well:

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

However when I am trying to put a border to both of them using \fbox or \frame the new line command \\ returns an error! If I remove it there will be no error but the subfigures do not align vertically anymore.

How can I have both vertical alignment for the figures and a border surrounding both of them at the same time?

  • For one thing, the \fbox is bigger than the subfigures, one of which is at least \textwidth wide. – John Kormylo Jul 14 '16 at 17:15
  • BTW, which subfigure package are you using? There are many, and most of them are obsolete. – John Kormylo Jul 14 '16 at 17:22
  • I use MikTex 2.9 which takes care of downloading the packages automatically and I use this command '\usepackage[tight,footnotesize]{subfigure}' to include subfigure commands – Polla A. Fattah Jul 14 '16 at 17:31
2

Here are two different ways to handle \\ inside a \fbox, depending on whether you know the width needed. Actually, with the tabular you don't even need \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}
3

A very simple solution with the framed environment:

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

enter image description here

2

One more alternative:

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

Package subfigure is considered obsolete and replaced with subfig. However, I suggest to use more advanced subcaption and its environment subfigure.

enter image description here

2

A solution with tcolorbox was missing:

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

enter image description here

  • +1. Approved :-) – Sebastiano Apr 4 '19 at 10:15

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.