# Figure with two graphics and one matrix

I want to recreate this figure in latex: https://developer.nvidia.com/discover/convolution I dont quite managed to algin the matrix and the images.

This is how I tried it:

\begin{figure}
\centering
\begin{tabular}{c c c}
\includegraphics[width=0.2\textwidth]{Grundlagen/Bilder/Freature_1.png}
&
$\displaystyle \begin{bmatrix} -1 & -1 & -1 \\ -1 & 8 & -1 \\ -1 & -1 & -1 \\ \end{bmatrix}$
&
\includegraphics[width=0.2\textwidth]{Grundlagen/Bilder/Freature_2.png}
\end{tabular}
\end{figure}


I would appreciate any help.

This is the result:

## 3 Answers

You can exploit the fact that a tabular is vertically centered with respect to the baseline (actually, not exactly, but it's not so important).

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\centering

\begin{tabular}{c c c}
Input image &
\begin{tabular}{@{}c@{}} Convolution \\ kernel \end{tabular} &
Feature map \\
\begin{tabular}{@{}c@{}}
\includegraphics[width=0.2\textwidth]{example-image}
\end{tabular} &
$\begin{bmatrix} -1 & -1 & -1 \\ -1 & 8 & -1 \\ -1 & -1 & -1 \\ \end{bmatrix}$ &
\begin{tabular}{@{}c@{}}
\includegraphics[width=0.2\textwidth]{example-image}
\end{tabular}
\end{tabular}

\caption{How the convolution kernel works}

\end{figure}

\end{document}


With tabularray and adjustbox packages:

\documentclass{article}
\usepackage{amsmath}
\usepackage[export]{adjustbox}
\usepackage{tabularray}

\begin{document}
\begin{figure}
\centering
\begin{tblr}{width=82mm,
colsep=3pt,
colspec={X[c] X[c, mode=dmath] X[c] },
row{1} = {mode=text}
}
Input image & Convolution Kernel & Feature map  \\
\includegraphics[width=\linewidth,valign=m]{example-image-a}
&   \begin{bmatrix}
-1 & -1 & -1 \\
-1 & \hfill 8 & -1 \\
-1 & -1 & -1 \\
\end{bmatrix}
&   \includegraphics[width=\linewidth,valign=m]{example-image-b}
\end{tblr}
\end{figure}
\end{document}


You could do this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{M{2.5cm}  M{2.6cm}  M{2.5cm}}
Input image & Convolution Kernel & Feature map\\[0.5cm]
\includegraphics[width=0.2\textwidth]{example-image-a}
&%
\vfill$\displaystyle\begin{bmatrix} -1 & -1 & -1 \\ -1 & \hfill 8 & -1 \\ -1 & -1 & -1 \\ \end{bmatrix}$\vfill
&
\includegraphics[width=0.2\textwidth]{example-image-b}
\end{tabular}
\end{figure}
\end{document}


• I forgot to mention that I want to add the text above the images aswell and with your approch the text is not centered? May 21 at 23:18
• @HWilmer Update the answer.
– Tom
May 21 at 23:29