LaTeX中单元格表格的垂直对齐

5
我用Latex创建了这个表格: Table 您可以看到数据集一列中的文字(MNIST,CIFAR10等)没有垂直对齐。我该如何将这些字符串放置在单元格的中间? 这是我的代码:
\begin{table}[!hbt]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{|c|c|c|c|c|}
    \hline
    Category & Epochs per round & Dataset & FedAvg & FedCurv \\
    \hline
    \multirow{9}{2.5cm}{\centering Uniform Distribution} &  1 & MNIST & accuracy & accuracy \\ 
    & 10 &  & accuracy & accuracy \\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & CIFAR10  & accuracy & accuracy\\
    & 10 &  & accuracy & accuracy\\ 
    & 30 &  & accuracy & accuracy \\\cline{2-5}
    & 1 & TinyImageNet & accuracy & accuracy \\
    & 10 &  & accuracy & accuracy \\
    & 30 &  & accuracy & accuracy \\
    \hline
    \multirow{9}{2.5cm}{\centering Quantity Skew} &  1 & MNIST & accuracy & accuracy \\ 
    & 10 &  & accuracy & accuracy \\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & CIFAR10 & accuracy & accuracy\\
    & 10 & & accuracy & accuracy\\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & TinyImageNet & accuracy & accuracy \\
    & 10 & & accuracy & accuracy\\
    & 30 &  & accuracy & accuracy \\
    \hline
    \multirow{9}{2.5cm}{\centering Quantity Labels Skew} &  1 & MNIST & accuracy & accuracy \\ 
    
...

    \multirow{9}{2.5cm}{\centering Covariate Shift} & 1 & MNIST & accuracy & accuracy \\ 
    & 10 & & accuracy & accuracy \\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & CIFAR10 & accuracy & accuracy\\
    & 10 &   & accuracy & accuracy\\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & TinyImageNet  & accuracy & accuracy \\
    & 10 &  & accuracy & accuracy\\
    & 30 &  & accuracy & accuracy \\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

2
将来请不要发布代码片段,而是制作一个可编译的 [mre]。 - samcarter_is_at_topanswers.xyz
1个回答

5
我建议使用tabularray包代替传统的表格。
不相关的问题,但请勿在浮动体中使用center环境,这会增加额外的垂直间距。你可以使用\centering代替。
\documentclass{article}

\usepackage{tabularray}

\begin{document}


\begin{table}[!hbt]
\caption{Multi-row table}
%\begin{center}
\centering
\begin{tblr}{|c|c|c|c|c|}
    \hline
    Category & Epochs per round & Dataset & FedAvg & FedCurv \\
    \hline
    \SetCell[r=9]{} Uniform Distribution &  1 & \SetCell[r=3]{} MNIST & accuracy & accuracy \\ 
    & 10 &  & accuracy & accuracy \\ 
    & 30 &  & accuracy & accuracy \\ \cline{2-5}
    & 1 & \SetCell[r=3]{}CIFAR10  & accuracy & accuracy\\
    & 10 &  & accuracy & accuracy\\ 
    & 30 &  & accuracy & accuracy \\\cline{2-5}
    & 1 & \SetCell[r=3]{}TinyImageNet & accuracy & accuracy \\
    & 10 &  & accuracy & accuracy \\
    & 30 &  & accuracy & accuracy \\
    \hline
\end{tblr}
%\end{center}
\label{tab:multicol}
\end{table}

\end{document}

enter image description here


谢谢,我不知道SetCell - CasellaJr
1
@CasellaJr SetCell是新的tabularray包中最好的功能之一。这使得它比传统表格更容易使用。 - samcarter_is_at_topanswers.xyz
这样,我的表太长了,一页放不下。我可以在这里展示还是需要提一个新问题? - CasellaJr
@CasellaJr 请提出一个新问题,包括可编译的 [mre]。 - samcarter_is_at_topanswers.xyz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接