5

Say, i have a text file

10.0123235 5.0234324
11.2342345 6.02343256

where the first column is value and the second is a standard deviation.

I am trying to figure out how to automatically put it into a table with \pm sign using pgfplotstable? So what i want to be in table is $10\pm5$ and $11\pm6$.

Should be something in style like

\pgfplotstabletypeset[
    columns={0},
    columns/0/.style={
         column name={$value$},
         postproc cell content/.style={
              @cell content=##0$\pm$##1
         }
    }
   ]...

but it does not work...

UPDATE: here is a minimal LaTeX example:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{eurosym}
\usepackage{amsmath}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}
\pgfplotstabletypeset[
    columns={0},
    columns/0/.style={
         column name={$0$},
         postproc cell content/.append style={
           /pgfplots/table/@cell content/.add={}{$\pm$ ##2 }
        }
    }
]{
10.0123235 & 5.0234324 \\
11.2342345 & 6.02343256
}
\end{table}
\end{document}

UPDATE2:

almost working example, the question is : how to control precision in numbers?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{eurosym}
\usepackage{amsmath}
\usepackage{pgfplotstable}
\begin{document}

\pgfplotstableread{
10.0123235  5.0234324 
11.2342345  6.02343256
}\loadedtable

\pgfplotstablecreatecol[
   create col/assign/.code={%
         \getthisrow{0}\entry
         \getthisrow{1}\dev
         \edef\entry{\entry$\pm$\dev}%
         \pgfkeyslet{/pgfplots/table/create col/next content}\entry
   }]
  {new}\loadedtable

\begin{table}
\pgfplotstabletypeset[
    columns={new},
    columns/new/.style={
         string type,
         column name={$new$},
    }
]\loadedtable
\end{table}
\end{document}

UPDATE3: I found a nice topic on printing complex numbers. It is actually very similar to what i want to achieve... Trying to bend their result to my needs...

Denis
  • 225

2 Answers2

1

Here is a working example:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepackage{pgfplotstable}

\def\pgfmathprintpmnumber#1#2{%
    \pgfmathfloatparsenumber{\thisrow{#1}}%
    \let\valueRe=\pgfmathresult
    \pgfmathfloatparsenumber{\thisrow{#2}}%
    \let\valueIm=\pgfmathresult
    \edef\valueRe{\noexpand\pgfmathprintnumber[fixed zerofill]{\valueRe}}%
    %\show\valueRe
    \edef\valueIm{\noexpand\pgfmathprintnumber[fixed zerofill]{\valueIm}}%
    %\show\valueIm
    \toks0=\expandafter{\valueRe}%
    \toks1=\expandafter{\valueIm}%
    % we cannot use \edef\value{\valueRe\valueIm} as this would
    % expand \pgfmathprintnumber - which is not expandable.
    % Writing \the<tokenregister> expands the content of
    % <tokenregister> exactly once:
    \edef\value{\the\toks0 & $\pm$\the\toks1 }%
}


\begin{document}

\pgfplotstableread{
10.0123235  5.0234324 
11.2342345  6.02343256
}\loadedtable

\begin{table}
\pgfplotstabletypeset[
  columns/C11/.style={string type, column type={r@{}l}, column name={$c11$}},
  create on use/C11/.style={%
    create col/assign/.code={%
       \pgfmathprintpmnumber{0}{1}
       \pgfkeyslet{/pgfplots/table/create col/next content}\value
    }
  },
  columns={C11}
  ]{\loadedtable}
\end{table}

\end{document}

which is a light modification of this answer.

Denis
  • 225
1

This functionality can also be achieved with the collcell package:

enter image description here

Below, I defined two column types, V for the numerical value column and E for error. The V column stores the integer result in \Value and this gets printed with the error in the E column.

Code:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{collcell}

\newcommand{\Value}{}% \newcommand{\Error}{}%

\newcommand{\SetValue}[1]{\pgfmathparse{int(floor(#1))}\xdef\Value{\pgfmathresult}} \newcommand{\DisplayValueAndError}[1]{\pgfmathparse{int(floor(#1))}$\Value \pm \pgfmathresult$}

\newcolumntype{V}{>{\collectcell\SetValue}{l}<{\endcollectcell}} \newcolumntype{E}{>{\collectcell\DisplayValueAndError}{l}<{\endcollectcell}}

\begin{document}

\begin{tabular}{V E} 10.0123235 & 5.0234324 \ 11.2342345 & 6.02343256 \ \end{tabular}

\end{document}

Peter Grill
  • 223,288