4

I currently want to depicting how an algorithm is working. The algorithm is using three different steps, which are repeatedly called.

So I want a result like this:

Whised result

But I currently only get

Current

My source:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    \centering
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
\end{figure}

\end{document}

I already had the idea to add two dummy images to archive my wished result

\subcaptionbox{}{
    \phantomcaption
    \begin{tikzpicture}
    \draw[opacity=0] (0, 0) rectangle (4, 2.5);
    \end{tikzpicture}
}

But using of phantomcaption only result in changed caption (always "a" instead of "e" and "f", whereas I expected a removed caption)

3
  • 1
    Remove \centering.
    – erik
    Commented Mar 10, 2015 at 19:57
  • I don't want remove \centering, because left and right spacing should be same.
    – SunBlack
    Commented Mar 10, 2015 at 20:28
  • Perhaps \hfill\mbox{}
    – cmhughes
    Commented Mar 10, 2015 at 20:41

4 Answers 4

7

You can use two \phantom images:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    \centering
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }\par
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
        \phantom{\begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}}
        \phantom{\begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}}%
\end{figure}

\end{document}

enter image description here

4

Use a tabular:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
\centering
\begin{tabular}{@{}l@{ }l@{ }l@{}}
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
&
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
&
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
\\
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
\end{tabular}
\end{figure}

\end{document}

Note the protection against spurious spaces given by % at the end of some lines.

enter image description here

1

Simple solution

If you want the subfigure to take the full text width, don't use \centering and put \hfill between each subfigure

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    %\centering
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \hfill
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \hfill
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    } \\
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
\end{figure}

\end{document}

visu

1

A solution with the floatrow package:

\documentclass{scrbook}

\usepackage{pgfplots}
%\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage{floatrow}
\DeclareFloatVCode{myrowsep}{\vskip 2.5ex}

%\usepackage[showframe]{geometry}

\begin{document}
\setcounter{chapter}{1}
Test
\begin{figure}[h]
\floatsetup{justification =centering, rowpostcode=myrowsep}
\ffigbox{
\begin{subfloatrow}[3]
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-a}}
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-b}}
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-c}}
\end{subfloatrow}
\begin{subfloatrow}[3]
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-d}}
\hspace*{0.667\linewidth}
\end{subfloatrow}
}
{\caption{Four images}\label{4im}}
\end{figure}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .