Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
    
Could you please provide a fully compilable example (MWE)? It would help the solvers a lot! –  Malipivo May 5 at 17:27
    
@Malipivo hi. I updated the question with minimal example. –  Denis May 5 at 18:39
    
Does this help tex.stackexchange.com/a/123075/3235? –  percusse May 5 at 22:15
    
@percusse it does, but it does not have rounding. I think to round up numbers one need all those tricks with toks0/toks1. btw, that's exactly what i did in Update2!.. –  Denis May 5 at 22:28
    
You can just use pretty printing of numbers instead of toks such as \pgfmathprintnumber[fixed,precision=5]{...} etc. –  percusse May 6 at 6:59

2 Answers 2

up vote 1 down vote accepted

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}
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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