我有一张表格,希望所有单元格都垂直居中。我添加了以下行
\renewcommand\tabularxcolumn[1]{m{#1}}
根据另一篇帖子但我得到了不一致的结果,一些单元格居中,但一些单元格不居中:
自行车(与行人相反)不在中心,PFG卡在了顶行。如何才能让所有内容垂直居中?
以下是代码:
\begin{table}
\centering
\caption{to do}
\label{tab:law}
\begin{tabularx}{0.49\textwidth}{cX|XXX}
\toprule[1.5pt]
& & Japan & Germany & France \\
\midrule[1.5pt]
\multirow{2}{*}{\usymH{1F6B8}{12pt}} & Fine for red light violation & x & y & z \\
\cline{2-5}
{} & PFG & - & - & - \\
\midrule[1.5pt]
\multirow{2}{*}{\usymH{1F6B4}{12pt}} & Driving on sidewalk & x & y & z \\
\cline{2-5}
{} & Fine for red light violation & - & - & - \\
\bottomrule[1.5pt]
\end{tabularx}
\end{table}
PS:附加问题,有没有办法让垂直线连续?
答案1
tblr
有了新的 LaTeX3 包环境,一切都变得轻而易举tabularray
:
\documentclass{article}
\usepackage{utfsym}
\usepackage{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}
\centering
\caption{to do}
\label{tab:law}
\begin{tblr}{width=0.68\textwidth,colspec={cX[l,m]|X[l,m]X[l,m]X[l,m]}}
\toprule[1.5pt]
& & Japan & Germany & France \\
\midrule[1.5pt]
\SetCell[r=2]{l}\usymH{1F6B8}{12pt} & Fine for red light violation & x & y & z \\
\cline{2-5}
& PFG & - & - & - \\
\midrule[1.5pt]
\SetCell[r=2]{l}\usymH{1F6B4}{12pt} & Driving on sidewalk & x & y & z \\
\cline{2-5}
& Fine for red light violation & - & - & - \\
\bottomrule[1.5pt]
\end{tblr}
\end{table}
\end{document}