You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Beamer的表格单元格中实现文本垂直居中?

Beamer表格单元格文本底部对齐问题解决

使用Beamer类制作表格时,单元格内的文本会默认呈底部对齐状态。试过多种常见解决方案(包括multicolumn、multirow、parbox、minipage、嵌套tabular环境等)都没有效果,以下是最小复现代码:

\documentclass{beamer}

\usepackage{diagbox}
\usepackage{array}

\begin{document}
   
  \begin{frame}
     \begin{center}
       \vspace{\baselineskip}
       \begin{table}
       \begin{tabular}{|m{3cm}|c|c|}
          \hline
          \diagbox[width=3cm]{Text}{Text} & Text & Text\\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
       \end{tabular}
       \end{table}
     \end{center}
  \end{frame}

\end{document}

解决方案1:使用adjustbox包调整图片基线

加载adjustbox包,将图片的基线对齐到顶部,让文本与图片顶部对齐:

\documentclass{beamer}

\usepackage{diagbox}
\usepackage{array}
\usepackage{adjustbox} % 引入adjustbox包

\begin{document}
   
  \begin{frame}
     \begin{center}
       \vspace{\baselineskip}
       \begin{table}
       \begin{tabular}{|m{3cm}|c|c|}
          \hline
          \diagbox[width=3cm]{Text}{Text} & Text & Text\\
          \hline
          Text & \adjustbox{valign=t}{\includegraphics[width=3cm]{example-image-a}}  & \adjustbox{valign=t}{\includegraphics[width=3cm]{example-image-a}} \\
          \hline
          Text & \adjustbox{valign=t}{\includegraphics[width=3cm]{example-image-a}}  & \adjustbox{valign=t}{\includegraphics[width=3cm]{example-image-a}} \\
          \hline
       \end{tabular}
       \end{table}
     \end{center}
  \end{frame}

\end{document}

解决方案2:改用tabularray包(现代表格工具)

tabularray包对单元格对齐的支持更直观,无需复杂调整即可实现预期效果:

\documentclass{beamer}

\usepackage{tabularray}
\usepackage{diagbox}

\begin{document}
   
  \begin{frame}
     \begin{center}
       \vspace{\baselineskip}
       \begin{table}
       \begin{tblr}{|m{3cm}|c|c|}
          \hline
          \diagbox[width=3cm]{Text}{Text} & Text & Text\\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
       \end{tblr}
       \end{table}
     \end{center}
  \end{frame}

\end{document}

解决方案3:重定义array包的m列对齐方式

通过重定义m列的行为,强制文本顶部对齐:

\documentclass{beamer}

\usepackage{diagbox}
\usepackage{array}

% 重定义m列为顶部对齐的自定义列类型
\renewcommand{\arraystretch}{1.2} % 可选,调整行高优化显示
\newcolumntype{M}[1]{>{\vtop\bgroup\hsize=#1\arraybackslash}p{#1}<{\egroup}}

\begin{document}
   
  \begin{frame}
     \begin{center}
       \vspace{\baselineskip}
       \begin{table}
       \begin{tabular}{|M{3cm}|c|c|}
          \hline
          \diagbox[width=3cm]{Text}{Text} & Text & Text\\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
       \end{tabular}
       \end{table}
     \end{center}
  \end{frame}

\end{document}

内容的提问来源于stack exchange,提问作者Leonardo Castro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 01:37:25