我对在 latex 中制作一个单元格内有图形的表格有一些疑问。我需要一个表格,比如说 3 行 2 列。我要在第二列内放一张图片。为了做到这一点,我发现使用表格环境多行命令,但当我要使用多个相互关联的表格时,它会变得非常混乱。那么,我如何才能以堆叠形式制作这样的表格,并有足够的间距并在单元格内容纳一个图形?
以下代码与我正在使用的代码类似。如果您有任何建议,我将不胜感激。
\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}
答案1
作为多行表格的替代方案,您可以使用sidebyside
tcolorbox
。下面是一个可能的解决方案。默认情况下, atcolorbox
使用所有可用的水平空间,但您可以强制其大小。
\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}
答案2
如果内容高于其跨越的行,我认为不会\multirow
扩展。您的图像高于 的四个表格行\multirow
,因此它们会突出\multirow
。如果您查看文件.log
或编辑器给出的警告列表,您会发现包含图像的行有两个过满的垂直框,这意味着图像高于放置它们的框。
另一种方法是使用嵌套的,tabular
而不是\multirow
。也就是说,
\begin{tabular}{p{4cm} l}
\begin{tabular}{l}
...
\end{tabular} &
\includegraphics[height=3cm,valign=c]{example-image-a}
\end{tabular}
您可以像这样添加多行,但您可能希望以 结束行\\[1.7cm]
,其中1.7cm
略大于图像高度的一半。由于包valign
中的选项,图像在基线上垂直居中adjustbox
。
\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
。
另一种方法是将图像放在 之外tabular
,并使用\colorbox
代替\rowcolor
:
\colorbox{black!10}{%
\begin{tabular}{p{4cm}}
...
\end{tabular}%
\includegraphics[scale=.35,valign=c]{example-image}%
}
行尾有百分号是因为代码中的换行符与空格相同,因此如果没有它们,您会在那些位置获得额外的水平空间(参见%
行末百分号 ( ) 有什么用?。
valign
我使用的选项默认\includegraphics
情况下不存在,它由 提供\usepackage[export]{adjustbox}
。如上所述,它的作用是将图像垂直居中在基线上,而默认是将图像的底部放在基线上。
\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}