有人愿意帮我把表格内容居中吗?由于某种原因,我的文本被移到了每个单元格的底部,中间和最右边的垂直线没有完全闭合。
\begin{table}[h]
\small
\begin{center}
\caption{\small{Example}\label{table:1}
\begin{tabular}{|c|c|c|}
\hline\\
$1$ & $2$ & $3$\\
\hline\\
$\{x, y, z\}$&
{\includegraphics[height=1.7 cm]{1}}&
$\begin{array}{c}
1\\
2\\
3\\
4\\
\end{array}$\\
\hline\\
$\{1, 2, 3, 4\}$&
{\includegraphics[height=1.7 cm]{2}}&
$\begin{array}{c}
1\\
2\\
3\\
\end{array}$\\
\hline\\
$\{5, 6, 7\}$&
{\includegraphics[height=1.7 cm]{3}}&
$\{1, 2, 3, 4\}$\\
\hline
\end{tabular}
\end{center}
\end{table}
答案1
像这样:
首先,我清理了代码中所有不必要的\\
(在 之后\hline
)和多余的反斜杠。借助包makecell
替换嵌套数组、将包adjustbox
中的图像居中放置在单元格中,并添加垂直边距:
\documentclass{article}
\usepackage{graphicx}
\usepackage[font=small]{caption}
\usepackage[export]{adjustbox}
\usepackage{array,makecell}
\begin{document}
\begin{table}[htb]
\small
\centering
\caption{Example}
\label{table:1}
\begin{tabular}{|*{3}{>{$}c<{$}|}}
\hline
1 & 2 & 3 \\
\hline
\{x, y, z\} & \includegraphics[height=1.7cm, margin=0pt 3pt, valign=M]{example-image-a}
& \makecell{
1\\
2\\
3\\
4} \\
\hline
\{1, 2, 3, 4\} & \includegraphics[height=1.7cm, margin=0pt 3pt, valign=M]{example-image-b}
& \begin{array}{c}% to see that between use of array and makecell is not difference
1\\
2\\
3
\end{array} \\
\hline
\{5, 6, 7\} & \includegraphics[height=1.7cm, margin=0pt 3pt, valign=M]{example-image-c}
& \{1, 2, 3, 4\} \\
\hline
\end{tabular}
\end{table}
\end{document}