如何在 LaTex 表格环境中将 table 单元格中的文本垂直居中?

How to center text vertically in table cell in LaTex tabular environment?

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

\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}

请,请,请看看如何创建漂亮的 tables,例如user manual of the booktabs package。将您的数据放入数据监狱是不好的。制作斑马纹table更糟。同时做这两件事太可怕了。

\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}