3

Is there a way to prevent extra space being added between the figure and its caption when using \subfigure?

I am using a command posted in this topic where a \subfigure is added using the \phantomsubfigure command.

When using this command it adds extra space between my figure and its caption. Is there a way to suppress it?

Here is my MWE:

\documentclass[
DIV=11,
%fontsize=12,
twoside=semi, 
headinclude=false,
titlepage=firstiscover,
abstract=true,
headsepline=true,
footsepline=true,
chapterprefix=true, 
headings=big,
bibliography=totoc,
captions=tableheading
]{scrreprt}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage{setspace}
\usepackage{afterpage} %to float a figure onto its own page
\usepackage[draft]{graphicx}
\usepackage[labelformat=empty,skip=0pt]{subcaption}


%%%%%%%%%%% PHANTOM SUBFIGURE COMMAND
% Used for adding subfigure referencing capabilities to composite figure images
\newcommand*\phantomsubfigure[1]{\begin{subfigure}[]{0pt}\caption{}\label{#1}\end{subfigure}} %<---- this is the command
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
\begin{figure}[htb]
  \centering
  \includegraphics[width=16cm,height=23cm]{myPictureName.png}
  \caption{Figure without subfigures.}
  \label{fig:1}
\end{figure}

\begin{figure}[htb]
  \centering
  \includegraphics[width=16cm,height=23cm]{myPictureName.png}
  \phantomsubfigure{fig:S01+04-xrd_a}
  \phantomsubfigure{fig:S01+04-xrd_b}
  \phantomsubfigure{fig:S01+04-xrd_c}
  \phantomsubfigure{fig:S01+04-xrd_d}
  \phantomsubfigure{fig:S01+04-xrd_e}
  \caption{Figure with subfigures.}
  \label{fig:2}
\end{figure}

\end{document}
Fiztban
  • 2,071

1 Answers1

2

You are introducing some spurious white spaces by calling the subfigure environment on and on again. This environment is not meant to be called after an \includegraphics and therefore does not handle the white space introduced by the new line. You have to end that line with a %. I redefined your \phantomsubfigure in order to prevent you from this error for all the following occurrences.

% arara: pdflatex

\documentclass[%
    ,DIV=11
    ,twoside=semi
    ,headinclude=false
    ,headsepline=true
    ,footsepline=true
    ,headings=big
    ]{scrreprt}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=3cm]{geometry}
\usepackage[draft]{graphicx}
\usepackage[labelformat=empty,skip=0pt]{subcaption}

\newcommand*\phantomsubfigure[1]{\begin{subfigure}{0pt}\caption{}\label{#1}\end{subfigure}\ignorespaces} % put ignore spaces here...
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
    \begin{figure}[htb]
        \centering
        \includegraphics[width=16cm,height=23cm]{myPictureName.png}
        \caption{Figure without subfigures.}
        \label{fig:1}
    \end{figure}

    \begin{figure}[htb]
        \centering
        \includegraphics[width=16cm,height=23cm]{myPictureName.png}% <= this one is mandatory
        \phantomsubfigure{fig:S01+04-xrd_a}
        \phantomsubfigure{fig:S01+04-xrd_b}
        \phantomsubfigure{fig:S01+04-xrd_c}
        \phantomsubfigure{fig:S01+04-xrd_d}
        \phantomsubfigure{fig:S01+04-xrd_e}
        \caption{Figure with subfigures.}
        \label{fig:2}
    \end{figure}    
\end{document}
LaRiFaRi
  • 43,807