1

using subfig package is there any possibility to show a caption of first sub figure on top and for the other one at the bottom.

I am using the below code for displaying the two subfigures.

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{subfig}
\usepackage{tabularx}

\begin{document}

    \begin{figure}
                \subfloat[Caption 1]{\includegraphics[width=7cm]{1.png}} \\
                \subfloat[Caption 2]{\includegraphics[width=7cm]{2.png}}
        \caption{Figure Description}\label{foo}
    \end{figure}

\end{document}
  • No. At least none of the options listed on pages 8-9 of the manual allow captions on top. OTOH, you could easily create your own version using a minipage and \savebox. – John Kormylo Nov 2 '17 at 14:29
  • Since these are not side by side, why even bother with \subfloats? Just use \subcaption. – John Kormylo Nov 2 '17 at 15:03
2

It was easier to create two commands than add a second optional argument. If the use of top and bottom is counter-intuitive to you, feel free to rename them.

BTW, all position=top does is reverse \abovecaptionskip and \belowcaptionskip.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\newsavebox{\subfloatbox}

\newcommand{\topfloat}[2][\empty]% #1 = caption, #2=image
 {\savebox\subfloatbox{#2}%
  \begin{minipage}[t]{\wd\subfloatbox}
    \usebox\subfloatbox
    \subcaption{#1}
  \end{minipage}}

\newcommand{\bottomfloat}[2][\empty]% #1 = caption, #2=image
 {\savebox\subfloatbox{#2}%
  \begin{minipage}[b]{\wd\subfloatbox}
    \captionsetup{position=top}%
    \subcaption{#1}
    \usebox\subfloatbox
  \end{minipage}}

\begin{document}

    \begin{figure}
                \bottomfloat[Caption 1]{\includegraphics[width=7cm]{1.png}} \\
                \topfloat[Caption 2]{\includegraphics[width=7cm]{2.png}}
        \caption{Figure Description}\label{foo}
    \end{figure}

\end{document}

An even simpler solution. Note that \subcaption has to be inside a group or it will cause a permanent change to \@captype.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}

    \begin{figure}
        \centering
        {\captionsetup{position=top}
            \subcaption{Caption 2}
            \includegraphics[width=7cm]{1.png}}\\
        {\includegraphics[width=7cm]{2.png}
            \subcaption{Caption 1}}
        \caption{Figure Description}\label{foo}
    \end{figure}

\end{document}
  • Thanks for your reply but in your answer the captions are getting created between two figures. I want the Caption 1 to be on top of sub-figure. – TechJ Nov 2 '17 at 15:23
  • Presto chango, she is done! – John Kormylo Nov 2 '17 at 15:29

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.