[英]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}
请,请,请看一下如何创建漂亮的表格,例如booktabs
包的用户手册。 将您的数据放入数据监狱是不好的。 制作斑马条桌更糟。 同时做这两件事真是太可怕了。
\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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.