问题描述
我想水平和垂直地将每个单元格中的文本居中。使用下面的代码,文本将水平居中放置,而不是垂直居中放置,并显示在单元格的顶部。预先感谢!
\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}
解决方法
请,请,请看看如何创建美观的表格,例如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}