我有下表,其中报告的值精确到小数点后四位。但是我希望将其更改为小数点后三位,并采用 % 格式。例如,从 0.9919 到 99.1。任何关于如何做到这一点的想法都很棒!谢谢
\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{pdflscape}
\usepackage{booktabs, makecell}
\usepackage{siunitx}
\begin{document}
\begin{landscape}
\begin{table}
\caption {TreeSHAP recursive prediction \\ This table demonstrates the classification to etc. Panel A, Panel B, Panel C, and Panel D. Describe sample, etc.}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l
*{4}{*{3}{S[table-format=1.3]}S[table-format=4.0]}
}
\toprule
& \multicolumn{4}{c}{\thead{ET TreeSHAP}}
& \multicolumn{4}{c}{\thead{ET Approx TreeSHAP}}
& \multicolumn{4}{c}{\thead{RF TreeSHAP}}
& \multicolumn{4}{c}{\thead{RF Approx TreeSHAP}} \\
\cmidrule(l){2-5}
\cmidrule(l){6-9}
\cmidrule(l){10-13}
\cmidrule(l){14-17}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}} \\
\cmidrule(l){2-3}
\cmidrule(l){4-5}
\cmidrule(l){6-7}
\cmidrule(l){8-9}
\cmidrule(l){10-11}
\cmidrule(l){12-13}
\cmidrule(l){14-15}
\cmidrule(l){16-17}
& {\thead{AUC}} & {\thead{Accuracy}} & {\thead{AUC}} & {\thead{Accuracy}}
& {\thead{AUC}} & {\thead{Accuracy}} & {\thead{AUC}} & {\thead{Accuracy}}
& {\thead{AUC}} & {\thead{Accuracy}} & {\thead{AUC}} & {\thead{Accuracy}}
& {\thead{AUC}} & {\thead{Accuracy}} & {\thead{AUC}} & {\thead{Accuracy}}
\\
\midrule\addlinespace
\multicolumn{17}{l}{\textit{Panel A: XYZ}} \\
\addlinespace
50 & {0.9919} & {0.8896} & {0.9940} & {0.9088} & {0.9913} & {0.8865} & {0.9947} & {0.9068} & {0.9973} & {0.9404} & {0.9987} & {0.9519} & {0.9975} & {0.9417} & {0.9984} & {0.9525} \\
40 & {0.9917} & {0.8887} & {0.9912} & {0.9049} & {0.9909} & {0.8824} & {0.9944} & {0.8957} & {0.9970} & {0.9358} & {0.9952} & {0.9475} & {0.9973} & {0.9399} & {0.9984} & {0.9510} \\
30 & {0.9909} & {0.8811} & {0.9938} & {0.8953} & {0.9890} & {0.8667} & {0.9919} & {0.8852} & {0.9968} & {0.9355} & {0.9951} & {0.9469} & {0.9965} & {0.9305} & {0.9981} & {0.9438} \\
20 & {0.9870} & {0.8536} & {0.9904} & {0.8602} & {0.9885} & {0.8633} & {0.9902} & {0.8750} & {0.9948} & {0.9109} & {0.9939} & {0.9265} & {0.9954} & {0.9165} & {0.9937} & {0.9317} \\
10 & {0.9848} & {0.8307} & {0.9867} & {0.8442} & {0.9847} & {0.8349} & {0.9888} & {0.8458} & {0.9818} & {0.8063} & {0.9882} & {0.8300} & {0.9860} & {0.8381} & {0.9913} & {0.8555} \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel B: XYZ}} \\
\addlinespace
50 & {0.9964} & {0.9440} & {0.9976} & {0.9501} & {0.9960} & {0.9394} & {0.9976} & {0.9465} & {0.9972} & {0.9491} & {0.9986} & {0.9566} & {0.9974} & {0.9516} & {0.9986} & {0.9599} \\
40 & {0.9961} & {0.9409} & {0.9971} & {0.9452} & {0.9956} & {0.9362} & {0.9976} & {0.9438} & {0.9970} & {0.9429} & {0.9986} & {0.9504} & {0.9974} & {0.9484} & {0.9987} & {0.9558} \\
30 & {0.9943} & {0.9209} & {0.9970} & {0.9307} & {0.9954} & {0.9348} & {0.9974} & {0.9348} & {0.9969} & {0.9399} & {0.9984} & {0.9494} & {0.9971} & {0.9438} & {0.9982} & {0.9504} \\
20 & {0.9912} & {0.8963} & {0.9943} & {0.9067} & {0.9949} & {0.9286} & {0.9973} & {0.9359} & {0.9962} & {0.9325} & {0.9977} & {0.9376} & {0.9964} & {0.9339} & {0.9984} & {0.9443} \\
10 & {0.9781} & {0.8184} & {0.9880} & {0.8265} & {0.9644} & {0.7578} & {0.9808} & {0.7718} & {0.9871} & {0.8641} & {0.9934} & {0.8772} & {0.9859} & {0.8592} & {0.9930} & {0.8738} \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel C: XYZ}} \\
\addlinespace
50 & {0.9262} & {0.5418} & {0.9587} & {0.5556} & {0.9261} & {0.5416} & {0.9584} & {0.5450} & {0.9972} & {0.9401} & {0.9983} & {0.9465} & {0.9973} & {0.9411} & {0.9987} & {0.9479} \\
40 & {0.9241} & {0.5378} & {0.9569} & {0.5407} & {0.9237} & {0.5369}& {0.9578} & {0.5422} & {0.9972} & {0.9400} & {0.9983} & {0.9468} & {0.9970} & {0.9367} & {0.9987} & {0.9466} \\
30 & {0.9186} & {0.5229} & {0.9545} & {0.5397} & {0.9225} & {0.5403} & {0.9578} & {0.5500} & {0.9965} & {0.9314} & {0.9981} & {0.9412} & {0.9966} & {0.9335} & {0.9982} & {0.9424} \\
20 & {0.9141} & {0.5132} & {0.9528} & {0.5225} & {0.9177} & {0.5180} & {0.9547} & {0.5305} & {0.9959} & {0.9255} & {0.9977} & {0.9361} & {0.9963} & {0.9317} & {0.9979} & {0.9368} \\
10 & {0.9002} & {0.4655} & {0.9456} & {0.4790} & {0.8909} & {0.4526} & {0.9416} & {0.4587} & {0.8843} & {0.3997} & {0.9322} & {0.3963} & {0.9940} & {0.9014} & {0.9929} & {0.9107} \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel D: XYZ}} \\
\addlinespace
50 & {0.9958} & {0.9403} & {0.9907} & {0.9478} & {0.9958} & {0.9398} & {0.9953} & {0.9513} & {0.9974} & {0.9449} & {0.9892} & {0.9575} & {0.9974} & {0.9433} & {0.9889} & {0.9540} \\
40 & {0.9955} & {0.9379} & {0.9838} & {0.9465} & {0.9955} & {0.9394} & {0.9924} & {0.9488} & {0.9974} & {0.9455} & {0.9974} & {0.9548} & {0.9972} & {0.9430} & {0.9970} & {0.9536} \\
30 & {0.9947} & {0.9330} & {0.9868} & {0.9411} & {0.9949} & {0.9372} & {0.9834} & {0.9434} & {0.9971} & {0.9428} & {0.9885} & {0.9521} & {0.9969} & {0.9412} & {0.9960} & {0.9513} \\
20 & {0.9937} & {0.9246} & {0.9829} & {0.9357} & {0.9931} & {0.9182} & {0.9814} & {0.928} & {0.9967} & {0.9360} & {0.9878} & {0.9473} & {0.9963} & {0.9364} & {0.9960} & {0.9451} \\
10 & {0.9659} & {0.7426} & {0.9666} & {0.7456} & {0.9771} & {0.7927} & {0.9740} & {0.8037} & {0.9958} & {0.9289} & {0.9874} & {0.9399} & {0.9948} & {0.9221} & {0.9873} & {0.9289} \\
\bottomrule
\end{tabular*}
\end{table}
\end{landscape}
\end{document}
答案1
S
如果您使用{}
周围的数据,那么您就打败了列。
但是,这里S
不能使用列,因为无法用条目进行计算。不过,这可能是一个不错的功能。
collcell
您可以使用和功能模拟工作expl3
。xparse
如果您的 LaTeX 系统不是最新的,请加载。
\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{pdflscape}
\usepackage{booktabs, makecell}
\usepackage{siunitx}
\usepackage{collcell,xfp}
\ExplSyntaxOn
\newcommand{\makepercent}[1]
{
\fp_set:Nn \l_tmpa_fp { round(#1*100,1) }
\fp_compare:nT { \l_tmpa_fp < 10 } { \hphantom{0} }
\fp_eval:n { \l_tmpa_fp }
\fp_compare:nT { \l_tmpa_fp = floor(\l_tmpa_fp) } { \hphantom{.0} }
}
\ExplSyntaxOff
\begin{document}
\begin{landscape}
\begin{table}
\caption {TreeSHAP recursive prediction \\
This table demonstrates the classification to etc.
Panel A, Panel B, Panel C, and Panel D. Describe sample, etc.}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l
*{16}{>{\collectcell\makepercent}c<{\endcollectcell}}
}
\toprule
& \multicolumn{4}{c}{\thead{ET TreeSHAP}}
& \multicolumn{4}{c}{\thead{ET Approx TreeSHAP}}
& \multicolumn{4}{c}{\thead{RF TreeSHAP}}
& \multicolumn{4}{c}{\thead{RF Approx TreeSHAP}}\\
\cmidrule{2-5} \cmidrule{6-9} \cmidrule{10-13} \cmidrule{14-17}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}
& \multicolumn{2}{c}{\thead{CV}}
& \multicolumn{2}{c}{\thead{Test}}\\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
\cmidrule{10-11} \cmidrule{12-13} \cmidrule{14-15} \cmidrule{16-17}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
& \multicolumn{1}{c}{\thead{AUC}} & \multicolumn{1}{c}{\thead{Accuracy}}
\\
\midrule
\addlinespace
\multicolumn{17}{l}{\textit{Panel A: XYZ}} \\
\addlinespace
50 & 0.9919 & 0.8896 & 0.9940 & 0.9088 & 0.9913 & 0.8865 & 0.9947 & 0.9068 & 0.9973 & 0.9404 & 0.9987 & 0.9519 & 0.9975 & 0.9417 & 0.9984 & 0.9525 \\
40 & 0.9917 & 0.8887 & 0.9912 & 0.9049 & 0.9909 & 0.8824 & 0.9944 & 0.8957 & 0.9970 & 0.9358 & 0.9952 & 0.9475 & 0.9973 & 0.9399 & 0.9984 & 0.9510 \\
30 & 0.9909 & 0.8811 & 0.9938 & 0.8953 & 0.9890 & 0.8667 & 0.9919 & 0.8852 & 0.9968 & 0.9355 & 0.9951 & 0.9469 & 0.9965 & 0.9305 & 0.9981 & 0.9438 \\
20 & 0.9870 & 0.8536 & 0.9904 & 0.8602 & 0.9885 & 0.8633 & 0.9902 & 0.8750 & 0.9948 & 0.9109 & 0.9939 & 0.9265 & 0.9954 & 0.9165 & 0.9937 & 0.9317 \\
10 & 0.9848 & 0.8307 & 0.9867 & 0.8442 & 0.9847 & 0.8349 & 0.9888 & 0.8458 & 0.9818 & 0.8063 & 0.9882 & 0.8300 & 0.9860 & 0.8381 & 0.9913 & 0.8555 \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel B: XYZ}} \\
\addlinespace
50 & 0.9964 & 0.9440 & 0.9976 & 0.9501 & 0.9960 & 0.9394 & 0.9976 & 0.9465 & 0.9972 & 0.9491 & 0.9986 & 0.9566 & 0.9974 & 0.9516 & 0.9986 & 0.9599 \\
40 & 0.9961 & 0.9409 & 0.9971 & 0.9452 & 0.9956 & 0.9362 & 0.9976 & 0.9438 & 0.9970 & 0.9429 & 0.9986 & 0.9504 & 0.9974 & 0.9484 & 0.9987 & 0.9558 \\
30 & 0.9943 & 0.9209 & 0.9970 & 0.9307 & 0.9954 & 0.9348 & 0.9974 & 0.9348 & 0.9969 & 0.9399 & 0.9984 & 0.9494 & 0.9971 & 0.9438 & 0.9982 & 0.9504 \\
20 & 0.9912 & 0.8963 & 0.9943 & 0.9067 & 0.9949 & 0.9286 & 0.9973 & 0.9359 & 0.9962 & 0.9325 & 0.9977 & 0.9376 & 0.9964 & 0.9339 & 0.9984 & 0.9443 \\
10 & 0.9781 & 0.8184 & 0.9880 & 0.8265 & 0.9644 & 0.7578 & 0.9808 & 0.7718 & 0.9871 & 0.8641 & 0.9934 & 0.8772 & 0.9859 & 0.8592 & 0.9930 & 0.8738 \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel C: XYZ}} \\
\addlinespace
50 & 0.9262 & 0.5418 & 0.9587 & 0.5556 & 0.9261 & 0.5416 & 0.9584 & 0.5450 & 0.9972 & 0.9401 & 0.9983 & 0.9465 & 0.9973 & 0.9411 & 0.9987 & 0.9479 \\
40 & 0.9241 & 0.5378 & 0.9569 & 0.5407 & 0.9237 & 0.5369& 0.9578 & 0.5422 & 0.9972 & 0.9400 & 0.9983 & 0.9468 & 0.9970 & 0.9367 & 0.9987 & 0.9466 \\
30 & 0.9186 & 0.5229 & 0.9545 & 0.5397 & 0.9225 & 0.5403 & 0.9578 & 0.5500 & 0.9965 & 0.9314 & 0.9981 & 0.9412 & 0.9966 & 0.9335 & 0.9982 & 0.9424 \\
20 & 0.9141 & 0.5132 & 0.9528 & 0.5225 & 0.9177 & 0.5180 & 0.9547 & 0.5305 & 0.9959 & 0.9255 & 0.9977 & 0.9361 & 0.9963 & 0.9317 & 0.9979 & 0.9368 \\
10 & 0.9002 & 0.4655 & 0.9456 & 0.4790 & 0.8909 & 0.4526 & 0.9416 & 0.4587 & 0.8843 & 0.3997 & 0.9322 & 0.3963 & 0.9940 & 0.9014 & 0.9929 & 0.9107 \\
\addlinespace
\multicolumn{17}{l}{\textit{Panel D: XYZ}} \\
\addlinespace
50 & 0.9958 & 0.9403 & 0.9907 & 0.9478 & 0.9958 & 0.9398 & 0.9953 & 0.9513 & 0.9974 & 0.9449 & 0.9892 & 0.9575 & 0.9974 & 0.9433 & 0.9889 & 0.9540 \\
40 & 0.9955 & 0.9379 & 0.9838 & 0.9465 & 0.9955 & 0.9394 & 0.9924 & 0.9488 & 0.9974 & 0.9455 & 0.9974 & 0.9548 & 0.9972 & 0.9430 & 0.9970 & 0.9536 \\
30 & 0.9947 & 0.9330 & 0.9868 & 0.9411 & 0.9949 & 0.9372 & 0.9834 & 0.9434 & 0.9971 & 0.9428 & 0.9885 & 0.9521 & 0.9969 & 0.9412 & 0.9960 & 0.9513 \\
20 & 0.9937 & 0.9246 & 0.9829 & 0.9357 & 0.9931 & 0.9182 & 0.9814 & 0.928 & 0.9967 & 0.9360 & 0.9878 & 0.9473 & 0.9963 & 0.9364 & 0.9960 & 0.9451 \\
10 & 0.9659 & 0.7426 & 0.9666 & 0.7456 & 0.9771 & 0.7927 & 0.9740 & 0.8037 & 0.9958 & 0.9289 & 0.9874 & 0.9399 & 0.9948 & 0.9221 & 0.9873 & 0.9289 \\
\bottomrule
\end{tabular*}
\end{table}
\end{landscape}
\end{document}
我不会添加%
到每个条目中;在标题中指定数据是百分比。
我删除了所有(l)
规范\cmidrule
:它们不需要tabular*
设置\tabcolsep
为零。
无需更改表格主体,即可以“绝对”格式打印数据:只需将表格序言更改为
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l
*{16}{S[table-format=1.4]}
}
答案2
这是我在文本编辑器中做的编辑,我使用 vim
:%s/\d.\(\d\d\)\(\d\)\d/\% \1\.\2/gc
应该可以。每次更改前它都会询问你。如果你想让它更改所有更改而不进一步询问,只需删除末尾的 c 即可。
因此,匹配一个数字(你的 0)一个句点,捕获两个数字,捕获一个数字,匹配最后一位数字。
然后它用 \% 替换(两个 \ 因为你想转义结果中的 %,而 vim 需要 \\% 才能以 \% 结尾)。你得到 % \d\d.\d
在乳胶中也许可以做到这一点,但要使用合适的工具。