gpt4 book ai didi

latex - 单元格表 Latex 中的垂直对齐

转载 作者:行者123 更新时间:2023-12-05 03:25:42 24 4
gpt4 key购买 nike

我在 Latex 中创建了这个表: Table如您所见,Dataset 列中的文本(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}

最佳答案

我建议使用 tabularray 包而不是传统的表格。

与问题无关,但不要在 float 中使用 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

关于latex - 单元格表 Latex 中的垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71921641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com