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

enter image description here

解决方法

请,请,请看看如何创建美观的表格,例如user manual of the booktabs package。将您的数据放入数据监狱很糟糕。制作斑马带桌更糟。同时做这两项简直太可怕了。

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

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

{
\setlength{\extrarowheight}{30pt}
\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 \\[30pt] \hline
\end{tabular}
}

\end{document}

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...