TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My data contains a column with numbers like 0.01 or 0.9412 which I want to display as 1.00% and 94.12% . I would like to declare the column by means of dec sep align. How can I do that?

[This question arose after the answer for PGFplotstable: Is it possible to set a number format for a *row* instead of a column? has been accepted. I add it as separate answer to simplify searching]

share|improve this question
up vote 11 down vote accepted

The key idea is to use

  1. a preprocessing style which multiplies the values by 100

  2. a postprocessing style which appends the percent sign

However, the postprocessing style is applied to two cells because dec sep align creates two artifical cells. The manual states that \pgfplotstablepartno can be used to identify which part is currently being postprocessed. A complete solution could be

enter image description here

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstabletypeset[
    columns/A/.style={
        column type=r,
        dec sep align,
        preproc/expr={100*##1},
        postproc cell content/.append code={
            \ifnum1=\pgfplotstablepartno
                \pgfkeysalso{@cell content/.add={}{\%}}%
            \fi
        },
        fixed,
        fixed zerofill,
    },
]
{
 A
 0.01
 1
 0.1234
 0.5
}

\end{document}
share|improve this answer
    
That is some deep magic. Thank you, it worked flawlessly! – Trevor Aug 3 '12 at 22:07
    
I posted a follow-up answer explaining how to make this work for rows instead of columns at the original question: tex.stackexchange.com/questions/65546/… – Trevor Aug 3 '12 at 22:13

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.