3

So I have the following code, which produces a table with some values:

\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}

I would like to put a slightly larger separation between columns 4 and 5 and 8 and 9 (counting the first column as 0). I have tried many tricks, but it's time I ask someone more knowledgeable about the proper way to do it.

P.S. Extra credit for whoever helps me set all the 12 columns through a loop.

Thanks, Peter

3

To adjust the size of a gap in tabular one uses @{\hspace{...}}. This is accomplished with pgfplotstable using the column type/.add={pre}{post} keyword. Then the only problem is that the column names and \multicolumns use the added space while centering. (Note that decimal aligned columns each count as two columns.)

\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}

demo

  • Maybe help \cmidrule(l{2em}){2-9} \cmidrule(r){10-17} ... – Zarko Dec 6 '16 at 8:44
  • @Zarko - You are right about removing the left trim from the second \cmidrule. Is that a typo on the first? – John Kormylo Dec 6 '16 at 14:48
  • yes, it is tipo. the trim of the first cmidrule should stay as it was. – Zarko Dec 6 '16 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.