Pgfplotstable:列之间的距离

Pgfplotstable:列之间的距离

所以我有以下代码,它生成一个包含一些值的表:

\documentclass{standalone}

\usepackage{pgfplotstable, booktabs}

\addtolength{\tabcolsep}{-0.5pt}

\begin{document}
\pgfplotstableread{ % Read the data into a macro we call \datatable
2   0.06309297535714574 0.03154648767857287 0.006309297535714574    0.003154648767857287    1.77E-2 0.008838834764831844    0.0017677669529663686   0.0008838834764831843   0.05    0.025   0.005   0.0025
3   0.05    0.025   0.005   0.0025  0.006415002990995841    0.0032075014954979207   0.0006415002990995841   0.00032075014954979206  0.025   0.0125  0.0025  0.00125
4   0.0430676558073393  0.02153382790366965 0.004306765580733931    0.0021533827903669656   0.003125    0.0015625   0.0003125   0.00015625  0.0125  0.00625 0.00125 0.000625
5   0.03868528072345415 0.019342640361727077    0.0038685280723454157   0.0019342640361727078   0.001788854381999832    0.000894427190999916    0.00017888543819998318  0.00008944271909999159  0.00625 0.003125    0.000625    0.0003125
6   0.03562071871080222 0.01781035935540111 0.0035620718710802223   0.0017810359355401111   0.0011340230290662861   0.0005670115145331431   0.00011340230290662862  0.00005670115145331431  0.003125    0.0015625   0.0003125   0.00015625
7   0.03333333333333333 0.016666666666666666    0.003333333333333333    0.0016666666666666666   0.0007713560673657699   0.00038567803368288496  0.00007713560673657698  0.00003856780336828849  0.0015625   0.00078125  0.00015625  0.000078125
8   0.03154648767857287 0.015773243839286435    0.003154648767857287    0.0015773243839286436   0.0005524271728019902   0.0002762135864009951   0.00005524271728019902  0.00002762135864009951  0.00078125  0.000390625 0.000078125 0.0000390625
9   0.030102999566398114    0.015051499783199057    0.0030102999566398118   0.0015051499783199059   0.000411522633744856    0.000205761316872428    0.0000411522633744856   0.0000205761316872428   0.000390625 0.0001953125    0.0000390625    0.00001953125
10  0.02890648263178878 0.01445324131589439 0.0028906482631788784   0.0014453241315894392   0.00031622776601683794  0.00015811388300841897  0.00003162277660168379  0.000015811388300841894 0.0001953125    0.00009765625   0.00001953125   9.765625e-6
}\datatable

\pgfplotstabletypeset[
    /pgf/number format/sci superscript,
    /pgf/number format/zerofill,
    /pgf/number format/std,
    /pgf/number format/precision=2,
    columns/0/.style={
        column name={\(n\)},
        /pgf/number format/precision=0,
        /pgf/number format/sci zerofill
    },
    columns/1/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/2/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/3/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/4/.style={
        column name={\(0.005\)},
        dec sep align
    },
    columns/5/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/6/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/7/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/8/.style={
        column name={\(0.005\)},
        dec sep align
    },
    columns/9/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/10/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/11/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/12/.style={
        column name={\(0.005\)},
        dec sep align
    },
    every head row/.style={
    before row={
        \toprule
        & \multicolumn{8}{c}{\(k_{n} = k_{1} / \log_{2} (n+1)\)}
        & \multicolumn{8}{c}{\(k_{n} = k_{1} / n^{2.5}\)}
        & \multicolumn{8}{c}{\(k_{n} = k_{1} / 2^{n-1}\)} \\
        \cmidrule(lr){2-9}
        \cmidrule(lr){10-17}
        \cmidrule(lr){18-25}
    },
        after row=\midrule
    },
    every last row/.style={
        after row=\bottomrule
    }]{\datatable}
\end{document}

我想将第 4 列和第 5 列以及第 8 列和第 9 列之间的间隔稍微大一些(将第一列算作 0)。我尝试了很多技巧,但现在是时候向更了解正确方法的人请教了。

PS:如果有人能帮我通过循环设置所有 12 列,我将获得额外加分。

谢谢,彼得

答案1

要调整表格中间隙的大小,可以使用@{\hspace{...}}。这是通过 pgfplotstable 实现的,使用column type/.add={}{邮政}关键字。那么唯一的问题是列名和\multicolumns 在居中时使用了添加的空间。(请注意,小数对齐的列每列算作两列。)

\documentclass{standalone}

\usepackage{pgfplotstable, booktabs}

\addtolength{\tabcolsep}{-0.5pt}

\begin{document}
\pgfplotstableread{ % Read the data into a macro we call \datatable
2   0.06309297535714574 0.03154648767857287 0.006309297535714574    0.003154648767857287    1.77E-2 0.008838834764831844    0.0017677669529663686   0.0008838834764831843   0.05    0.025   0.005   0.0025
3   0.05    0.025   0.005   0.0025  0.006415002990995841    0.0032075014954979207   0.0006415002990995841   0.00032075014954979206  0.025   0.0125  0.0025  0.00125
4   0.0430676558073393  0.02153382790366965 0.004306765580733931    0.0021533827903669656   0.003125    0.0015625   0.0003125   0.00015625  0.0125  0.00625 0.00125 0.000625
5   0.03868528072345415 0.019342640361727077    0.0038685280723454157   0.0019342640361727078   0.001788854381999832    0.000894427190999916    0.00017888543819998318  0.00008944271909999159  0.00625 0.003125    0.000625    0.0003125
6   0.03562071871080222 0.01781035935540111 0.0035620718710802223   0.0017810359355401111   0.0011340230290662861   0.0005670115145331431   0.00011340230290662862  0.00005670115145331431  0.003125    0.0015625   0.0003125   0.00015625
7   0.03333333333333333 0.016666666666666666    0.003333333333333333    0.0016666666666666666   0.0007713560673657699   0.00038567803368288496  0.00007713560673657698  0.00003856780336828849  0.0015625   0.00078125  0.00015625  0.000078125
8   0.03154648767857287 0.015773243839286435    0.003154648767857287    0.0015773243839286436   0.0005524271728019902   0.0002762135864009951   0.00005524271728019902  0.00002762135864009951  0.00078125  0.000390625 0.000078125 0.0000390625
9   0.030102999566398114    0.015051499783199057    0.0030102999566398118   0.0015051499783199059   0.000411522633744856    0.000205761316872428    0.0000411522633744856   0.0000205761316872428   0.000390625 0.0001953125    0.0000390625    0.00001953125
10  0.02890648263178878 0.01445324131589439 0.0028906482631788784   0.0014453241315894392   0.00031622776601683794  0.00015811388300841897  0.00003162277660168379  0.000015811388300841894 0.0001953125    0.00009765625   0.00001953125   9.765625e-6
}\datatable

\pgfplotstabletypeset[
    /pgf/number format/sci superscript,
    /pgf/number format/zerofill,
    /pgf/number format/std,
    /pgf/number format/precision=2,
    columns/0/.style={
        column name={\(n\)},
        /pgf/number format/precision=0,
        /pgf/number format/sci zerofill
    },
    columns/1/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/2/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/3/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/4/.style={
        column name={\(0.005\)\rule{\dimexpr 2em-\tabcolsep}{0pt}},
        dec sep align,
        column type/.add={}{@{\hspace{2em}}}
    },
    columns/5/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/6/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/7/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/8/.style={
        column name={\(0.005\)\rule{\dimexpr 2em-\tabcolsep}{0pt}},
        dec sep align,
        column type/.add={}{@{\hspace{2em}}}
    },
    columns/9/.style={
        column name={\(0.1\)},
        dec sep align
    },
    columns/10/.style={
        column name={\(0.05\)},
        dec sep align
    },
    columns/11/.style={
        column name={\(0.01\)},
        dec sep align
    },
    columns/12/.style={
        column name={\(0.005\)},
        dec sep align
    },
    every head row/.style={
    before row={
        \toprule
        & \multicolumn{8}{c@{\hspace{2em}}}{\(k_{n} = k_{1} / \log_{2} (n+1)\)}
        & \multicolumn{8}{c@{\hspace{2em}}}{\(k_{n} = k_{1} / n^{2.5}\)}
        & \multicolumn{8}{c}{\(k_{n} = k_{1} / 2^{n-1}\)} \\
        \cmidrule(lr{2em}){2-9}
        \cmidrule(r{2em}){10-17}% using @{} removes 2\tabcolsep spacing, so no trim needed on left
        \cmidrule(r){18-25}
    },
        after row=\midrule
    },
    every last row/.style={
        after row=\bottomrule
    }]{\datatable}
\end{document}

演示

相关内容