# How to fit a cell of a table to a figure and arrange multiple tables

I have some questions about making a table in latex having a figure inside of a cell. I need to have a table, let's say 3 by 2 rows and columns. I am going to put an image inside of the second column. For doing this, I found it easy to use tabular environment with multirow command but it becomes so messy when I am going to use multiple tables proceeding each other. So, how could I make such tables in a stack form with enough spacing and fitting a figure inside of the cell?
The following code is like what I am using. I will appreciate if you have any suggestions.

\documentclass[10pt]{letter}
\usepackage{geometry}

\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{longtable}

\geometry{
paper=letterpaper, % Change to letterpaper for US letter
top=3cm, % Top margin
bottom=1.5cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
%showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype}

%% using appendix
\usepackage[toc,page]{appendix}

\signature{Hello} % Your name for the signature at the bottom

\begin{document}

\begin{letter}{''Me''}

\opening{\textbf{To whome it may concern (\cc{S Pat}}}

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\section{\textbf{References}}

\begin{center}
\title{table 0}
\begin{tabular}{p{4cm}p{10cm}}
\rowcolor{gray!10}
\rowcolor{gray!10}
\textbf{From: X}\\
\rowcolor{gray!10}
\textbf{To: Y}
\end{tabular}
\label{tb0}
\end{center}

I don not know why there is not enough space between tables. This is very disgusting.
\\ \\

\title{table 1}
\begin{tabular}{p{3cm}p{10cm}}
\rowcolor{gray!10}
\rowcolor{gray!10}
\textbf{From: X}\\
\rowcolor{gray!10}
\textbf{To: Y} \\
\rowcolor{gray!10}
\textbf{CC: Z} \\
\end{tabular}

\end{letter}

\end{document}


What I got is like the below:

As an alternative to tabular with multirow, you could use a sidebyside tcolorbox. Following you have a possible solution. By default a tcolorbox uses all available horizontal space, but you can force its size.

\documentclass[10pt]{letter}
\usepackage{geometry}

\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage[most]{tcolorbox}
%\usepackage{longtable}
%\usepackage{multirow}
%\usepackage{longtable}

\geometry{
paper=letterpaper, % Change to letterpaper for US letter
top=3cm, % Top margin
bottom=1.5cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
%showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype}

%% using appendix
\usepackage[toc,page]{appendix}

\signature{Hello} % Your name for the signature at the bottom

\begin{document}

\begin{letter}{''Me''}

\opening{\textbf{To whome it may concern (\cc{S Pat}}}

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\section{\textbf{References}}

\begin{tcolorbox}[bicolor, sidebyside, righthand width=10cm, colback=gray!10, colbacklower=white, fontupper=\bfseries, title=Table 0, label=tb0, halign lower=center, sidebyside align =top seam]
Date: Aug. 2017\\
From: X\\
To: Y
\tcblower
\includegraphics[scale=.35]{example-image-a}
\end{tcolorbox}

I don not know why there is not enough space between tables. This is very disgusting.
\\ \\

\begin{tcolorbox}[bicolor, sidebyside, righthand width=6cm, colback=gray!10, colbacklower=white, fontupper=\bfseries, title= Table 1, label=tb1, center, width=11cm, halign lower=center]
Date: Aug. 2017\\
From: X\\
To: Y
\tcblower
\includegraphics[scale=.35]{example-image-b}
\end{tcolorbox}

\end{letter}

\end{document}


I don't think \multirow will expand if the content is higher than the rows it spans. Your images are higher than the four table rows of the \multirow, so they protrude out of the \multirow. If you look in the .log file, or the list of warnings your editor give, you will find two overfull vboxes for the lines containing the images, meaning that the images are higher than the box in which they are placed.

An alternative might be to use a nested tabular instead of \multirow. That is, something like

\begin{tabular}{p{4cm} l}
\begin{tabular}{l}
...
\end{tabular} &
\includegraphics[height=3cm,valign=c]{example-image-a}
\end{tabular}


You can add multiple rows like this, but you might want to end the row with \\[1.7cm], where 1.7cm is a little bit more than half the height of the image. The image is vertically centered on the baseline due to the valign option from the adjustbox package.

\documentclass[10pt]{letter}
\usepackage{geometry}

\geometry{
paper=letterpaper, % Change to letterpaper for US letter
top=3cm, % Top margin
bottom=1.5cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
%showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype}

%% using appendix
\usepackage[toc,page]{appendix}

\signature{Hello} % Your name for the signature at the bottom

\begin{document}

\begin{letter}{''Me''}

\opening{\textbf{To whome it may concern (\cc{S Pat}}}

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\section{\textbf{References}}

\begin{center}
\rowcolors{1}{gray!10}{gray!10}
\begin{tabular}{p{4cm} l}
\begin{tabular}{l}
\textbf{Date: Aug. 2017}   \\
\textbf{From: X}\\
\textbf{To: Y}
\end{tabular} &
\includegraphics[height=3cm,valign=c]{example-image-a} \\[1.7cm]
\begin{tabular}{l}
\textbf{Date: Aug. 2017}   \\
\textbf{From: X}\\
\textbf{To: Y} \\
\textbf{CC: Z} \\
\end{tabular} &
\includegraphics[height=3cm,valign=c]{example-image-a} \\
\end{tabular}
\end{center}

\end{letter}

\end{document}


# \colorbox.

An alternative might be to place the image outside the tabular, and use a \colorbox instead of \rowcolor:

\colorbox{black!10}{%
\begin{tabular}{p{4cm}}
...
\end{tabular}%
\includegraphics[scale=.35,valign=c]{example-image}%
}


The percent signs at the end of lines are there because a linefeed in the code is the same as a space, so without them you get extra horizontal space in those locations (cf. What is the use of percent signs (%) at the end of lines?.)

The valign option I used for \includegraphics is not there by default, it is made available by \usepackage[export]{adjustbox}. As mentioned above, what it does is to center the image vertically on the baseline, while the default is to place the bottom of the image on the baseline.

\documentclass[10pt]{letter}
\usepackage{geometry}

\usepackage[table]{xcolor}    % loads also »colortbl«. Only with the table option
% and the export option adds a new option for \includegraphics,
% for the vertical alignment of images on the baseline

\geometry{
paper=letterpaper, % Change to letterpaper for US letter
top=3cm, % Top margin
bottom=1.5cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
%showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype}

%% using appendix
\usepackage[toc,page]{appendix}

\signature{Hello} % Your name for the signature at the bottom

\begin{document}

\begin{letter}{''Me''}

\opening{\textbf{To whome it may concern (\cc{S Pat}}}

\vspace{2\parskip} % Extra whitespace for aesthetics
\closing{Sincerely,}
\vspace{2\parskip} % Extra whitespace for aesthetics

\section{\textbf{References}}

\begin{center}
\colorbox{black!10}{%
\begin{tabular}{p{4cm}}
\textbf{Date: Aug. 2017}   \\
\textbf{From: X}\\
\textbf{To: Y}
\end{tabular}%
\includegraphics[scale=.35,valign=c]{example-image}%
}
\end{center}

The image was higher than the four rows in the multirow, so it protruded out of it.

\colorbox{black!10}{%
\begin{tabular}{p{3cm}}
\textbf{Date: Aug. 2017} \\
\textbf{From: X}\\
\textbf{To: Y} \\
\textbf{CC: Z} \\
\end{tabular}%
\includegraphics[scale=.35,valign=c]{example-image}%
}

\end{letter}
\end{document}