尽管我尽了最大努力,但目前为止什么都没用。我试图将“9:1”对齐为\multirow
,但通常最终只会得到一个illegal pream-token
错误。将 放入\multirow
内部\multicolumn
可以消除错误,但也会删除单元格的格式。这就是我想要的样子:
这是我的代码:
\documentclass[a4paper,twoside]{article}
\usepackage{array}
\usepackage{dcolumn}
\newcolumntype{,}{D{.}{.}{-2}}
\usepackage{colortbl}
\usepackage{multirow,multicol}
\usepackage{numprint}
\npdecimalsign{.}
\begin{document}
\scriptsize \begin{center}
\begin{tabular}{ | l | >{\npdecimalsign{:}}N{2}{3} | n{3}{1} | >{\centering}m{35px} c | >{\npafternum{ \%}}n{3}{1} | >{\npafternum{ \%}}n{3}{1} | >{\npafternum{ \%}}n{3}{1} | }
\hline
\multirow{3}{35px}{type} &
\multicolumn{1}{c|}{\multirow{3}{25px}{\centering item ratio}} &
\multicolumn{1}{c|}{\multirow{3}{20px}{\centering total count}} &
\multicolumn{2}{p{70px} |}{\multirow{2}{70px}{\scriptsize \centering expected number of each type per set}} &
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing at least one item}} &
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing duplicate items}}&
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing a specific item}}\\&&&&&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}\\\cline{4-5} &&&\centering total&\centering unique&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}\\
\hline
Type A&1.49&3&\multicolumn{1}{,}{0}&\multicolumn{1}{,|}{0}&54.5&11.1&32.3\\
Type B&1.15&8&\multicolumn{1}{,}{2}&\multicolumn{1}{,|}{2}&87.6&15.9&18.2\\
Type C&1.7&15&\multicolumn{1}{,}{3}&\multicolumn{1}{,|}{3}&98.7&47.6&33.2\\
Type D&1.1&19&\multicolumn{1}{,}{24}&\multicolumn{1}{,|}{13}&100&100&76.7\\
\hline
Type 1&\multirow{2}{*}{9.1}&11&\multicolumn{1}{,}{15}&\multicolumn{1}{,|}{9}&100&99.5&69.6\\
Type 2&&54&\multicolumn{1}{,}{170}&\multicolumn{1}{,|}{51}&100&100&96.8\\\hline
\multicolumn{1}{l}{Total}&\multicolumn{1}{l}{}&\multicolumn{1}{n{3}{1}}{110}&\multicolumn{1}{,}{214}&\multicolumn{1}{,}{78}&\multicolumn{3}{c}{}
\end{tabular}
\end{center}\normalsize
\end{document}
答案1
生成\multirow
一个框,它不能用作列N{2}{3}
说明符的参数。您可以做的是将的参数放在\multirow
单独的N{2}{3}
处理中(即在里面\multirow
而不是外面进行)。我使用\NP
我定义的命令执行此操作。您必须将放在\multirow
括号中以保护它免受N
主表格中的列处理的影响,或者更好的是,将其放在中\multicolumn{1}{l}
。但仅使用括号似乎效果很好。我12:1
在单元格中使用,只是为了证明它有效。
\documentclass[a4paper,twoside]{article}
\usepackage{array}
\usepackage{dcolumn}
\newcolumntype{,}{D{.}{.}{-2}}
\usepackage{colortbl}
\usepackage{multirow,multicol}
\usepackage{numprint}
\npdecimalsign{.}
\newcommand\NP[1]{\begin{tabular}{@{}>{\npdecimalsign{:}}N{2}{3}@{}}#1\end{tabular}}
\begin{document}
\scriptsize \begin{center}
\begin{tabular}{ | l | >{\npdecimalsign{:}}N{2}{3} | n{3}{1} | >{\centering}m{35px} c | >{\npafternum{ \%}}n{3}{1} | >{\npafternum{ \%}}n{3}{1} | >{\npafternum{ \%}}n{3}{1} | }
\hline
\multirow{3}{35px}{type} &
\multicolumn{1}{c|}{\multirow{3}{25px}{\centering item ratio}} &
\multicolumn{1}{c|}{\multirow{3}{20px}{\centering total count}} &
\multicolumn{2}{p{70px} |}{\multirow{2}{70px}{\scriptsize \centering expected number of each type per set}} &
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing at least one item}} &
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing duplicate items}}&
\multicolumn{1}{c|}{\multirow{3}{30px}[0.125em]{\tiny \centering probability of seeing a specific item}}\\&&&&&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}\\\cline{4-5} &&&\centering total&\centering unique&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}&\multicolumn{1}{c|}{}\\
\hline
Type A&1.49&3&\multicolumn{1}{,}{0}&\multicolumn{1}{,|}{0}&54.5&11.1&32.3\\
Type B&1.15&8&\multicolumn{1}{,}{2}&\multicolumn{1}{,|}{2}&87.6&15.9&18.2\\
Type C&1.7&15&\multicolumn{1}{,}{3}&\multicolumn{1}{,|}{3}&98.7&47.6&33.2\\
Type D&1.1&19&\multicolumn{1}{,}{24}&\multicolumn{1}{,|}{13}&100&100&76.7\\
\hline
Type 1& {\multirow{2}{*}{\NP{12.1}}} & 11 &\multicolumn{1}{,}{15}&\multicolumn{1}{,|}{9}&100&99.5&69.6\\
%Type 1&9.1&11&\multicolumn{1}{,}{15}&\multicolumn{1}{,|}{9}&100&99.5&69.6\\
Type 2&&54&\multicolumn{1}{,}{170}&\multicolumn{1}{,|}{51}&100&100&96.8\\\hline
\multicolumn{1}{l}{Total}&\multicolumn{1}{l}{}&\multicolumn{1}{n{3}{1}}{110}&\multicolumn{1}{,}{214}&\multicolumn{1}{,}{78}&\multicolumn{3}{c}{}
\end{tabular}
\end{center}\normalsize
\end{document}
答案2
和siunitx
:
\documentclass[a4paper,twoside]{article}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{booktabs}
\renewcommand{\theadfont}{\normalsize}
\begin{document}
\begin{table}
\centering
\setlength{\tabcolsep}{5pt}
\begin{tabular}{ ll *{2}{S[table-format=3]} S[table-format=2] *{3}{S[table-format=3.1]}}
\toprule
{\thead{type}} &
{\thead{item\\ ratio}} &
{\thead{total\\ count}} &
\multicolumn{2}{c}{\thead{expected number of\\ each type per set}} &
\multicolumn{3}{c}{\thead{probability in \% of seeing}}\\
\cmidrule(r){4-5} \cmidrule(l){6-8}
&&& {\thead{total}} & {\thead{unique}} &
{\thead{at least\\ one item}} &
{\thead{duplicate\\ items}}&
{\thead{specific\\ item}}\\
\midrule
Type A & 1:49 & 3 & 0 & 0 & 54.5 & 11.1 & 32.3 \\
Type B & 1:15 & 8 & 2 & 2 & 87.6 & 15.9 & 18.2 \\
Type C & 1:7 & 15 & 3 & 3 & 98.7 & 47.6 & 33.2 \\
Type D & 1:1 & 19 & 24 & 13 & 100 & 100 & 76.7 \\
\midrule
Type 1 & \multirow{2}{*}{9:1} & 11 & 15 & 9 & 100 & 99.5 & 69.6 \\
Type 2 & & 54 & 170 & 51 & 100 & 100 & 96.8 \\
\midrule
Total & & 110 & 214 & 78 & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}