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)

egreg
  • 1,121,712
SunBlack
  • 337

4 Answers4

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

Gonzalo Medina
  • 505,128
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

egreg
  • 1,121,712
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

fwachtel
  • 81
  • 1
  • 8
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

Bernard
  • 271,350