# How to fill table cells with an image

I'd like to fill the cells of my table with some pictures, but with my actual code, the pictures have a margin at the top, left and right and the lower part of the picture is behind the next cell. How can i fill the cell with my picture?

My code is:

 \begin{tabular}{l|@{}c@{}}
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Single-Linkage}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Minimaler Abstand aller Elementpaare aus den beiden Clustern\\ \\ $D(A, B) = \min\limits_{a \in A, b \in B} \{ d(a, b)\}$\\ \\ Dieses Verfahren neigt zur Kettenbildung.\end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} \includegraphics[height=.18\textheight,valign=b]{images/SingleLinkage.png}]}} \\ \hline
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Complete-Linkage}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Maximaler Abstand aller Elementpaare aus den beiden Clustern\\ \\ $D(A, B) = \max\limits_{a \in A, b \in B} \{ d(a, b)\}$\\ \\ Dieses Verfahren neigt zur Bildung kleiner Gruppen.\end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} Hier Bild 2 einfügen}} \\ \hline
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Average-Linkage}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Durchschnittlicher Abstand aller Elementpaare aus den beiden Clustern\\ \\ $D(A, B) = \frac{1}{|A||B|} \sum\limits_{x,y \in A \cup B}d(a, b)$ \medskip \end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} Hier Bild 3 einfügen}} \\ \hline
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Average-Group-Linkage}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Durchschnittlicher Abstand aller Elementpaare aus der Vereinigung von A und B\\ \\ $D(A, B) = \frac{1}{(|A| + |B|)(|A| + |B| - 1)} \sum\limits_{x,y \in A \cup B}d(x, y)$ \medskip \end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} Hier Bild 4 einfügen}} \\ \hline
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Centroid-Method}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Abstand der Zentren der beiden Cluster\\ \\ $D(A, B) = d( \overline{a}, \overline{b})$\\ \\ wobei $\overline{a}$ das Zentrum des Clusters A sei, $\overline{b}$ das des Clusters B.\end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} Hier Bild 5 einfügen}} \\ \hline
\rowcolor[HTML]{3166FF}
\multicolumn{1}{c|}{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Median-Method}} & \cellcolor[HTML]{6D93FF}{\color[HTML]{333333} } \\ \cline{1-1}
\rowcolor[HTML]{6D93FF}
{\color[HTML]{333333} \begin{tabular}[c]{@{}l@{}}Abstand der Zentren der beiden Cluster\\ \\ $D(A, B) = d(\overline{a}, \overline{m})$\\ \\ wobei $\overline{a}$ das Zentrum des Clusters A sei, $\overline{m}$ der Mittelwert aus den Clusterzentren \\des grünen und blauen Clusters.\end{tabular}} & \multirow{-2}{*}{\cellcolor[HTML]{6D93FF}{\color[HTML]{333333} Hier Bild 6 einfügen}} \\ \hline
\end{tabular}


And the table looks like this:

In the cells under the picture should also be inserted images

• Where exactly should the image be positioned and what happens if the image is taller than the corresponding contents in the left column? Where should the extra height go? Jul 3, 2021 at 13:18
• The image should fill the whole cell. So if the two cells at the left have together a height of 80px, then the image and the cell should also have a height/width of 80px. Jul 3, 2021 at 13:25
• Wouldn't that result in inconsistent image heights and widths? The "Average-Linkage" part, for example, would require a less tall (and if you want to keep the aspect ratio, also less wide) image than the "Median Method" part. Jul 3, 2021 at 13:46
• Although probably still a little different from the expected output, but what about the following tcolorbox-based approach? i.stack.imgur.com/p70mD.png Jul 3, 2021 at 13:58

I would write your table on the following way:

• use tabularx for table
• remove all nested tables
• equatins write as displaystyle math
• move baseline in X column cells to middle (by \renewcommand\tabularxcolumn[1]{m{#1}})
• move image baseline to vertical center by use valign=m defined in adjustbox package
• instead includegraphics use \\adjustimage:

Considering above, the MWE with first rows with tree images is:

\documentclass{article}
\usepackage{geometry}
\usepackage[table, x11names]{xcolor}
\usepackage{makecell, multirow, tabularx}

%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table}[htb]
\centering
\renewcommand\tabularxcolumn[1]{m{#1}}
valign=c,  margin=0pt 3pt 0pt 3pt}
\rowcolors{1}{Blue3}{DodgerBlue2}
\begin{tabularx}{\linewidth}{X | >{\columncolor[HTML]{6D93FF}}c }
&   \\
Minimaler Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \min\limits_{a \in A, b \in B} \{ d(a, b)\}$
Dieses Verfahren neigt zur Kettenbildung.
%
&   \\
Minimaler Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \min\limits_{a \in A, b \in B} \{ d(a, b)\}$
Dieses Verfahren neigt zur kleiner Gruppen.
%
&   \\
Minimaler Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \frac{1}{(|A| + |B|)(|A| + |B| - 1)} \sum\limits_{x,y \in A \cup B}d(x, y)$
\end{tabularx}
\end{table}
\end{document}


You can change colors of table as you like to have. I would not coloring rows with images.

• Nice, thank you :) Jul 3, 2021 at 18:23

Here's an alternative, tcolorbox-based approach:

To improve the readability of the text inside of the colored boxes, I'd enhance the contrast between background color and text color.

A combination of colback=mylightblue!50, colbacktitle=mydarkblue!50, with fonttitle=\bfseries\color{black} for example results in the following output:

If you use colback=mylightblue!50, colbacktitle=mydarkblue!60!black, and fonttitle=\bfseries instead, you end up with:

\documentclass{article}
\usepackage{geometry}

\usepackage[most]{tcolorbox}
\definecolor{mydarkblue}{HTML}{3166FF}
\definecolor{mylightblue}{HTML}{6D93FF}

\newtcolorbox{myColorBox}[1]{%
sidebyside,
sidebyside align=center,
lefthand width=0.75\linewidth,
arc=0pt,
left=2pt,right=2pt,top=2pt,bottom=2pt,
toptitle=2pt,bottomtitle=2pt,
colback=mylightblue,
colbacktitle=mydarkblue,
enhanced,
boxrule=0pt,
width=\textwidth,
sidebyside gap=15pt,
lower separated=false,
title={#1},
nobeforeafter,
fonttitle=\bfseries
}

\begin{document}

\noindent
Minimaler Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \min\limits_{a \in A, b \in B} \{ d(a, b)\}$
Dieses Verfahren neigt zur Kettenbildung.
\tcblower
\includegraphics[width=\linewidth]{example-image}
\end{myColorBox}
%
Maximaler Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \max\limits_{a \in A, b \in B} \{ d(a, b)\}$
Dieses Verfahren neigt zur Bildung kleiner Gruppen.
\tcblower
\includegraphics[width=\linewidth]{example-image}
\end{myColorBox}
%
Durchschnittlicher Abstand aller Elementpaare aus den beiden Clustern
$D(A, B) = \frac{1}{|A||B|} \sum\limits_{x,y \in A \cup B}d(a, b)$
\tcblower
\includegraphics[width=\linewidth]{example-image-10x16}
\end{myColorBox}
%
Durchschnittlicher Abstand aller Elementpaare aus der Vereinigung von A und B
$D(A, B) = \frac{1}{(|A| + |B|)(|A| + |B| - 1)} \sum\limits_{x,y \in A \cup B}d(x, y)$
\tcblower
\includegraphics[width=\linewidth]{example-image-16x9}
\end{myColorBox}
%
\begin{myColorBox}{Centroid-Method}
Abstand der Zentren der beiden Cluster
$D(A, B) = d( \overline{a}, \overline{b})$
wobei $\overline{a}$ das Zentrum des Clusters A sei, $\overline{b}$ das des Clusters B.
\tcblower
\includegraphics[width=\linewidth]{example-image}
\end{myColorBox}
%
\begin{myColorBox}{Median-Method}
Abstand der Zentren der beiden Cluster
$D(A, B) = d(\overline{a}, \overline{m})$
wobei $\overline{a}$ das Zentrum des Clusters A sei, $\overline{m}$ der Mittelwert aus den Clusterzentren des grünen und blauen Clusters.
\tcblower
\includegraphics[width=\linewidth]{example-image}
\end{myColorBox}

\end{document}