2

I need all the numbers in the first column to have the same exponent of ten, say 10^{-2}. It would be nice if the multiplier was placed not near the number, but in the header of the table.

\documentclass[]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{pgfplots, pgfplotstable}

\pgfplotstableread[]{
    X       Y    Xerror Yerror  Y2
    0       0    0       0     0
    0.022   0.4  0.005   0.1   0.66
    0.038   0.8  0.005   0.1   1.14
    0.058   1.2  0.005   0.1   1.74
    0.09    1.6  0.005   0.1   2.7
    0.101   2    0.005   0.1   3.03
    0.123   2.4  0.005   0.1   3.69
    0.130   2.8  0.005   0.1   3.9
}\datatable

\begin{document}

    \pgfplotstableset{
    columns={X,Y,Xerror,Yerror},
    columns/X/.style={
        column name={$x$, \si{\meter}},
        /pgf/number format/.cd, sci, sci zerofill, relative*={-3}
    },
    columns/Y/.style={
        column name={$F_\mathbf{elast}$, \si{\newton}},
        /pgf/number format/.cd, fixed, fixed zerofill,
    },
    columns/Xerror/.style={
        column name={$\Delta x$, \si{\meter}},
        /pgf/number format/.cd, relative*={-2}
    },
    columns/Yerror/.style={
        column name={$\Delta F_\mathbf{elast}$, \si{\newton}},
    },
    every head row/.style={
        before row={\toprule},
        after row={\midrule}
    },
    every last row/.style={after row=\bottomrule},
}
\pgfplotstabletypeset{\datatable}

\end{document}

Desired result should looks like in picture below

enter image description here

1 Answer 1

3

Instead of using relative*, you can use multiply by to scale the values. Then you just have to change the column name to contain the power of 10.

Also, there is no need to use /pgf/number format/.cd, pgfplotstable understands, that you want set the number format.

The code:

\documentclass[]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{pgfplots, pgfplotstable}

\pgfplotstableread[]{
    X       Y    Xerror Yerror  Y2
    0       0    0       0     0
    0.022   0.4  0.005   0.1   0.66
    0.038   0.8  0.005   0.1   1.14
    0.058   1.2  0.005   0.1   1.74
    0.09    1.6  0.005   0.1   2.7
    0.101   2    0.005   0.1   3.03
    0.123   2.4  0.005   0.1   3.69
    0.130   2.8  0.005   0.1   3.9
}\datatable

\begin{document}

    \pgfplotstableset{
    columns={X,Y,Xerror,Yerror},
    columns/X/.style={
        column name={$x$, \SI{e-2}{\meter}},
        multiply by=100,
        fixed, fixed zerofill,
    },
    columns/Y/.style={
        column name={$F_\mathbf{elast}$, \si{\newton}},
        fixed, fixed zerofill,
    },
    columns/Xerror/.style={
        column name={$\Delta x$, \SI{e-3}{\meter}},
        multiply by=1000
    },
    columns/Yerror/.style={
        column name={$\Delta F_\mathbf{elast}$, \si{\newton}},
    },
    every head row/.style={
        before row={\toprule},
        after row={\midrule}
    },
    every last row/.style={after row=\bottomrule},
}
\pgfplotstabletypeset{\datatable}

\end{document}

The result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .