首页 > 解决方案 > 如何在表格环境中垂直居中文本?

问题描述

我有一个包含 3 列的表格,其中前 2 列是图片,第三列是我对这些图片的评论,但评论“淹没”,它位于单元格的底部。

我试过用m{2cm}而不是c

\begin{tabularx}{\textwidth}{c c m{2cm}}

但没有变化。

在此处输入图像描述

\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
    \begin{tabularx}{\textwidth}{c c c}

     \textbf{O-Na} & \textbf{Na-Y} & \textbf{Comments} \\

     \includegraphics[width=0.3\linewidth]{pic1.png} & 
     \includegraphics[width=0.3\linewidth]{pic2.png} & 
     My comments. \\
    \end{tabularx}
\end{table}

我的文字在单元​​格的底部。

标签: latextabular

解决方案


提供了垂直居中图像的graphbox方便选项:align=c

\documentclass{article}

\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphbox} 
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\begin{document}

\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
    \begin{tabularx}{\textwidth}{XXX}
     \thead{O-Na} & \thead{Na-Y} & \thead{Comments} \\
     \includegraphics[width=\linewidth,align=c]{example-image-duck} & 
     \includegraphics[width=\linewidth,align=c]{example-image-duck} & 
     My comments. \\
    \end{tabularx}
\end{table}

\end{document}

在此处输入图像描述


推荐阅读