[Tex/LaTex] Vertical colorbar (in tikz) + subfigures (png)

pgfplotssubfloatstikz-pgf

I have an issue with the placement of a colorbar. The colorbar is defined separately in a tikz-environment, as suggested in this topic.

My goal is to place one colorbar together with 4 png pictures (in a 2×2 configuration) in one figure environment. The png-pictures are arranged in a 2×2-configuration via the subfigure-command (see code below). The pictures are nicely aligned, but how can I add a vertical colorbar to the right side, which is nicely aligned with the 2×2 subfigures (without distortion and maximum readability)? I've made several attempts, but unfortunately without any success. I've also consulted this topic, I've just found it while typing my question out, but it seems that it's not solved yet for a vertical colorbar.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{pgfplots,tikz}
\usepackage{mwe}
\begin{figure*}[t!]
\centering
\begin{subfigure}[t]{0.5\textwidth}
    \centering
    \includegraphics[ height=1cm, width=0.6\textwidth]{example-image-a};
   \end{subfigure}%
~ 
\begin{subfigure}[t]{0.5\textwidth}
    \centering
    \includegraphics[ height=1cm, width=0.6\textwidth]{example-image-b};
    \end{subfigure}
    \vskip\baselineskip
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
    \includegraphics[ height=1cm, width=0.6\textwidth]{example-image-c};
   \end{subfigure}%
~ 
\begin{subfigure}[t]{0.5\textwidth}
    \centering
    \includegraphics[ height=1cm, width=0.6\textwidth]{example-image-a};
    \end{subfigure}
\caption{Random Caption}
\end{figure*}
\end{document}

I hope that the question is clear enough. Any kind of help is much appreciated.

Best Answer

One option is to use a tabular with two columns of type m{<length>} (requires the array package) with centered content. The first column for the 2x2 array of images and the second column for the colorbar. A little example illustrating this approach (adjust the settings according to your needs):

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{pgfplots,tikz}
\usepackage{array}

\begin{document}

\begin{figure*}
\centering
\begin{tabular}{
  @{}>{\centering\arraybackslash}m{\dimexpr.8\textwidth-\tabcolsep\relax}
  >{\centering\arraybackslash}m{\dimexpr.1\textwidth-\tabcolsep\relax}@{}
  }
    \begin{subfigure}[t]{0.38\textwidth}
    \centering
    \includegraphics[ height=1.5cm, width=\textwidth]{example-image-a}
   \end{subfigure}\hfill
    \begin{subfigure}[t]{0.38\textwidth}
    \centering
    \includegraphics[ height=1.5cm, width=\textwidth]{example-image-b}
    \end{subfigure}\par\bigskip
    \begin{subfigure}[t]{0.38\textwidth}
    \centering
    \includegraphics[ height=1.5cm, width=\textwidth]{example-image-c}
   \end{subfigure}\hfill
   \begin{subfigure}[t]{0.38\textwidth}
    \centering
    \includegraphics[ height=1.5cm, width=\textwidth]{example-image-a}
   \end{subfigure}
   &
  \includegraphics{colorbar}
\end{tabular}
\caption{Random Caption}
\end{figure*}

\end{document}

The result:

enter image description here

The colorbar I used was produced by processing the following colorbar.tex:

\documentclass[border={-4pt 0pt 5pt 0pt}]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    hide axis,
    scale only axis,
    height=0pt,
    width=0pt,
    colormap/jet,
    colorbar horizontal,
    point meta min=18,
    point meta max=48,
    colorbar style={
        width=4cm,
        rotate=90,
        xtick={\empty},
    }
  ]
    \addplot [draw=none] coordinates {(0,0) (1,1)};
\end{axis}
\end{tikzpicture}

\end{document}
Related Question