2

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:

enter image description here

In the cells under the picture should also be inserted images

4
  • 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?
    – leandriis
    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.
    – Marco
    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.
    – leandriis
    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
    – leandriis
    Jul 3, 2021 at 13:58

2 Answers 2

1

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[export]{adjustbox}
\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}}
    \adjustboxset{height=.12\textheight,
                  valign=c,  margin=0pt 3pt 0pt 3pt}
\rowcolors{1}{Blue3}{DodgerBlue2}
\begin{tabularx}{\linewidth}{X | >{\columncolor[HTML]{6D93FF}}c }
\color[HTML]{FFFFFF} Single-Linkage 
    &   \\ 
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.
    &   \adjustimage{}{example-image-duck}          \\ 
%
\color[HTML]{FFFFFF} Average-Linkage
    &   \\
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.
    &   \adjustimage{}{example-image-duck}          \\
%
\color[HTML]{FFFFFF} Complete-Linkage
    &   \\
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)
    \]
    &   \adjustimage{}{example-image-duck}          \\
\end{tabularx}
    \end{table}
\end{document}

enter image description here

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

1
  • Nice, thank you :)
    – Marco
    Jul 3, 2021 at 18:23
0

Here's an alternative, tcolorbox-based approach:

enter image description here

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:

enter image description here

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

enter image description here

\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
\begin{myColorBox}{Single-Linkage}
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}
%
\begin{myColorBox}{Complete-Linkage}
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}
%
\begin{myColorBox}{Average-Linkage}
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}
%
\begin{myColorBox}{Average-Group-Linkage}
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}

You must log in to answer this question.

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