3

I'd like to arrange my 5 subfigures like this, where each column is the same width. It must compile with LuaLaTex. enter image description here

Basically there is a 2x2 matrix occupying the two left columns and two rows, and a 5th subfigure in the third row, vertically centered.

When I just use 5 subfigures in a figure environment, I get 3 in the toprow and 2 in the bottom row, but this kind of alignment would be better. Any tips/tricks?

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}

\title{MWE}
\begin{document}

\begin{figure}[h!t]
  \captionsetup[subfigure]{justification=centering}
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
      \fill[red] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:a}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[green] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:b}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[blue] (0,0) rectangle (2,2);
    \end{tikzpicture}
        \label{fig:c}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[black] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:d}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[magenta] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:e}
    \caption{}
  \end{subfigure}  
  \label{fig:completeFigure}
  \caption{Complete caption...}
\end{figure}

\end{document}

5
  • Can you post the code for your existing configuration using, say, example-image-a or whatever for the images? You can maybe box the first two columns and then align the box, but it depends a bit on the details e.g. use of captions etc.
    – cfr
    Commented Jul 8 at 17:41
  • @cfr added the current setup (it's in the wrong order as (c) is currently on the right, not (e). ). Every subfigure is a tikzpicture, all the subcaptions are empty (I just want the (a) (b) ... no text) Commented Jul 8 at 17:49
  • Thanks, but could you please make it so we can compile it as-is?
    – cfr
    Commented Jul 8 at 17:51
  • @cfr updated, it runs on overleaf. Commented Jul 8 at 18:01
  • Also added the requirement that is has to work with LuaLatex. Commented Jul 8 at 18:04

2 Answers 2

2

You can use the outer alignment option to adjust vertical alignment. Using b for every sub-figure is tantamount to using the default or any other value. One way to adjust the alignment of the final image is to add filler space to the first row, force the three to the second row and then set the height of the final image to zero to prevent unwanted space between the rows.

2-2-1

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}

\title{MWE}
\begin{document}

\begin{figure}[h!t]
  \captionsetup[subfigure]{justification=centering}
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
      \fill[red] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:a}
    \caption{}
  \end{subfigure}%
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[green] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:b}
    \caption{}
  \end{subfigure}%
  \hspace*{0.3\textwidth}\par
  \begin{subfigure}[c]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[blue] (0,0) rectangle (2,2);
    \end{tikzpicture}
        \label{fig:c}
    \caption{}
  \end{subfigure}%
  \begin{subfigure}[c]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[black] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:d}
    \caption{}
  \end{subfigure}%
  \begin{subfigure}[b][0pt]{0.3\textwidth}
    \centering
    \begin{tikzpicture}
    \fill[magenta] (0,0) rectangle (2,2);
    \end{tikzpicture}
    \label{fig:e}
    \caption{}
  \end{subfigure}  
  \label{fig:completeFigure}
  \caption{Complete caption...}
\end{figure}
\end{document}
3

You can use \valign TeX primitive. My code is based on \inspic from OpTeX but it is irrelevant for you. You can simply replace the macro \figure by your macro or your code. The core if the idea is the usage of \valign primitive at lines 6-10 in the following example:

\newbox\fig
\setbox\fig=\hbox{\picw=4cm\inspic{example-image.jpg}}
\def\figure#1{\vbox{\copy\fig \medskip \hbox to4cm{\hss#1\hss}}}
\def\figskip{\noalign{\kern15pt}}

\valign{\vfil#\vfil \cr
   \figure{a} \medskip \figure{c} \cr \figskip
   \figure{b} \medskip \figure{d} \cr \figskip
   \figure{e} \cr
}

\bye

[Image added by cfr] 2-2-1

If you want to try this example as is, use OpTeX.

3
  • Sorry. I can't figure out how to gobble optex page numbering. [Edit: maybe the same as plain? Not sure.]
    – cfr
    Commented Jul 8 at 18:29
  • 2
    \nopagenumbers works like in plain TeX. Moreover, the macro \directoutput \vbox{...} creates a page with the contents of the given box without margins. Something like "standalone" LaTeX class.
    – wipet
    Commented Jul 8 at 20:02
  • Thanks. I'll try to remember that.
    – cfr
    Commented Jul 8 at 20:14

You must log in to answer this question.

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