2

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{xcolor}    % loads also »colortbl«
\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

\address{200 }

\begin{document}

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

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

        I look forward to your reply.

        \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}
                \textbf{Date: Aug. 2017} & \multirow{3}{4em}{\includegraphics[scale=.35]{download1.jpeg}} \\
                \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}
            \textbf{Date: Aug. 2017} & \multirow{4}{4em}{\includegraphics[scale=.35]{Download2.jpg}} \\
            \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: enter image description here

1

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{xcolor}    % loads also »colortbl«
\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

\address{200 }

\begin{document}

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

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

        I look forward to your reply.

        \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}

enter image description here

0

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.

output of first code

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

\usepackage[export]{adjustbox}

\usepackage[table]{xcolor}    % loads also »colortbl«

\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

\address{200 }

\begin{document}

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

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

I look forward to your reply.

\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.

output of code

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

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

\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

\address{200 }

\begin{document}

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

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

I look forward to your reply.

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.