我有一张包含图片的表格,想让它们在单元格中垂直和水平居中。为此,我使用了\cellspacetoplimit
和,并使用自定义命令插入它们,但它们仍然接触到以下线条:\cellsapcebottomlimit
\newcommand\cincludegraphics[2][]{\raisebox{-0.5\height}{\includegraphics[#1]{#2}}}
我该如何修复它?
例子:
\begin{table}[H]
\centering
\caption{Interpretowane pokrycia terenu}
\label{tab:ndvi}
\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{Zabudowa} & \textbf{Woda} & \textbf{Las} & \textbf{Gunt orny} &
\textbf{Uprawa trwała} \\ \hline
\cincludegraphics[width=4.5cm]{../screeny/NDVI/NDVI_reklas_bud} &
\cincludegraphics[width=4.5cm]{../screeny/NDVI/NDVI_reklas_woda} &
\cincludegraphics[width=4.5cm]{../screeny/NDVI/NDVI_reklas_las} &
\cincludegraphics[width=4.5cm]{../screeny/NDVI/NDVI_reklas_rola} &
\cincludegraphics[width=4.5cm]{../screeny/NDVI/NDVI_reklas_laki} \\
\hline
\end{tabular}
\end{table}
答案1
以下内容可能会让您了解如何组合valign=c
、cellspace
和嵌套表格:
\documentclass{article}
\usepackage{graphicx}
\usepackage{cellspace}
\usepackage[export]{adjustbox}
\setlength{\cellspacetoplimit}{\tabcolsep}
\setlength{\cellspacebottomlimit}{\tabcolsep}
\begin{document}
\begin{tabular}{ScScSc}
\hline
\begin{tabular}{@{}Sc@{}}
\includegraphics[height=2cm, valign=c]{example-image} \\
\includegraphics[height=2cm, valign=c]{example-image}
\end{tabular}
& \includegraphics[height=4.4cm, valign=c]{example-image} &
\begin{tabular}{@{}Sc@{}}
\includegraphics[height=2cm, valign=c]{example-image} \\
\includegraphics[height=2cm, valign=c]{example-image}
\end{tabular} \\
\hline
\end{tabular}
\end{document}