我有一个绘制表格的代码。
\documentclass[conference]{IEEEtran}
\usepackage{algorithmic}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{booktabs}
\usepackage{caption,subcaption,tikz}
\usetikzlibrary{positioning}
\usepackage{siunitx}
\sisetup{per=slash, load=abbr}
\begin{document}
\begin{table}[h]
\caption{Distribution of class categories}
\label{tbl::Fam}
\centering
\begin{tabular}{@{} ll *{3}{S[table-format=3.0]} @{}}
\toprule
Column&Algorithm&{min}&{max}&{std.dev.}\\
\midrule
age&Original &9&28&100\\
&PrivBayes&2&95&96\\
&ThirdAlg &10&90&50\\
\addlinespace
education\_level&Original&7&28&98\\
&PrivBayes&2&6&96\\
&ThirdAlg &10&90&50\\
\midrule
\addlinespace
employer\_type&Original&13&2&10\\
&PrivBayes&2&100&100\\
&ThirdAlg &10&90&50\\
\addlinespace
marital\_status&Original&10&20&100\\
&PrivBayes&2&6&100\\
&ThirdAlg &10&90&50\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
我的问题是它没有将 {age, education_level, employee_type, marital_status} 垂直对齐到多行的中心。你能帮帮我吗?
答案1
如果您使用\multirow
-package multirow
,它们将垂直对齐。您没有指定此单元格应跨越多行,但插入了一个包含内容的单元格和两个空单元格。\multirow
不过请注意,您仍然必须在其他行中插入空单元格。
\documentclass[conference]{IEEEtran}
\usepackage{algorithmic}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{caption,subcaption,tikz}
\usetikzlibrary{positioning}
\usepackage{siunitx}
\sisetup{per=slash, load=abbr}
\begin{document}
\begin{table}[h]
\caption{Distribution of class categories}
\label{tbl::Fam}
\centering
\begin{tabular}{@{} ll *{3}{S[table-format=3.0]} @{}}
\toprule
Column&Algorithm&{min}&{max}&{std.dev.}\\
\midrule
\multirow{3}{*}{age}&Original &9&28&100\\
&PrivBayes&2&95&96\\
&ThirdAlg &10&90&50\\
\addlinespace
\multirow{3}{*}{education\_level}&Original&7&28&98\\
&PrivBayes&2&6&96\\
&ThirdAlg &10&90&50\\
\midrule
\addlinespace
\multirow{3}{*}{employer\_type}&Original&13&2&10\\
&PrivBayes&2&100&100\\
&ThirdAlg &10&90&50\\
\addlinespace
\multirow{3}{*}{marital\_status}&Original&10&20&100\\
&PrivBayes&2&6&100\\
&ThirdAlg &10&90&50\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
无需使用multirow
包裹。只需将物品放在{age, education_level, employer_type, marital_status}
它们当前所在位置的下一行即可……
\documentclass[conference]{IEEEtran}
\usepackage{algorithmic}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{booktabs}
\usepackage{caption,subcaption,tikz}
\usetikzlibrary{positioning}
\usepackage{siunitx}
\sisetup{per=slash, load=abbr}
\begin{document}
\begin{table}[h]
\caption{Distribution of class categories}
\label{tbl::Fam}
\centering
\begin{tabular}{@{} ll *{3}{S[table-format=3.0]} @{}}
\toprule
Column&Algorithm&{min}&{max}&{std.dev.}\\
\midrule
&Original &9&28&100\\
age&PrivBayes&2&95&96\\ % moved "age" down by 1 rows
&ThirdAlg &10&90&50\\
\addlinespace
&Original&7&28&98\\
education\_level&PrivBayes&2&6&96\\
&ThirdAlg &10&90&50\\
\addlinespace
\midrule
\addlinespace
&Original&13&2&10\\
employer\_type&PrivBayes&2&100&100\\
&ThirdAlg &10&90&50\\
\addlinespace
&Original&10&20&100\\
marital\_status&PrivBayes&2&6&100\\
&ThirdAlg &10&90&50\\
\bottomrule
\end{tabular}
\end{table}
\end{document}