2

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}
  • 1
    You have to type a % after each \phantomsubfigure and after the second \includegraphics or you put all that stuff on just one line. – LaRiFaRi Jun 17 '15 at 10:13
  • Neither seems to work for me on 2 different editors. – Fiztban Jun 17 '15 at 10:19
  • Scrap that I just made another foolish mistake the % works thank you – Fiztban Jun 17 '15 at 10:21
1

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}
  • Thank you for the explanation and solution, I did not know \ignorespaces existed. Have a nice day. – Fiztban Jun 17 '15 at 10:25
  • 1
    @Fiztban You are welcome. Have fun TeXing! – LaRiFaRi Jun 17 '15 at 10:27

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.