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

问题描述

我想将每个单元格中的文本水平和垂直居中。使用下面的代码,文本水平居中但不垂直居中,并显示在单元格的顶部。提前致谢!

\documentclass[jou]{apa7}
\usepackage{tabularx,colortbl}

\begin{document}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\begin{tabular}{| L{1cm} | C{5cm} | C{5cm} | C{5cm} |} \hline
\rowcolor[gray]{.4}& \color{white}Cell 1 & \color{white}Cell 2 & \color{white}Cell 3 \\[30pt] \hline
\cellcolor[gray]{.4}\color{white}Cell 4 & Cell 5 & Cell 6 & Cell 7 \\[100pt] \hline


\end{tabular}

\end{document}

在此处输入图像描述

标签: latextabular

解决方案


请,请,请看一下如何创建漂亮的表格,例如包的用户手册booktabs。将您的数据放入数据监狱是不好的。制作斑马线桌更糟糕。同时做这两件事真是太可怕了。

\documentclass[jou]{apa7}

\author{author names}
\shorttitle{subtitle}
\title{title}

\usepackage{tabularray}

\begin{document}


\noindent%
\begin{tblr}{
  hlines,
  vlines,
  row{1} = {bg=gray,fg=white},
  rows = {ht=2cm},
  columns = {halign=c},
  colspec = {Q[1cm,bg=gray,fg=white] XXX},
  } 
  & Cell 1 & Cell 2 & Cell 3 \\
  Cell 4 & Cell 5 & Cell 6 & Cell 7 \\
\end{tblr}


\end{document}

在此处输入图像描述


推荐阅读