latex - 如何在 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}
解决方案
请,请,请看一下如何创建漂亮的表格,例如包的用户手册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}
推荐阅读
- flutter - FileSystemException:无法打开文件,路径 = 'storage/emulated/0/DCIM/docs/myPdf.pdf'(操作系统错误:不允许操作,errno = 1)
- sql - 我如何选择所有从未做过跑步和游泳的举重运动员?
- android - 无法加载脚本:“确保您正在运行 Metro Server(运行'react-native start')”问题
- android - 每当点击被触发时如何随机播放列表
- http - 通过 HTTP(s) 发送 sql 命令(和接收选定数据)的缺点
- python - Python:如何从元组创建嵌套字典?
- xpath - Windows 任务计划程序 XPath 用于在一天中的某个小时过滤事件
- node.js - Loopback 3 在 EJS 视图中加载引导 CDN
- python - 将 Prophet 或 Auto ARIMA 与 Ray 结合使用
- javascript - 我在 html 中提取当前日期和时间的方式有问题吗?