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.

Using pgfplotstable, it's straightforward to set a column number format using

columns/(columnname)/.style={(format)}

What I would like to do is change the number format of a particular row. In my case, the last row of my table is in percent format, whereas the rest of the table is fixed point format.

Is there a way to set the number format of a row, that overrides the number format of all the columns?

As a follow-up question, is there a number format preset for percentages?

Cheers

EDIT: I've now got it closer to working, thanks to Christian. However, I'm now having an issue where two "%" signs appear in each of the columns that dec sep align creates. How can I remove the first one? See the last row of the image to understand what I mean.

enter image description here

share|improve this question
    
What do you mean by "number format preset for percentages"? Do you mean something which appends "%"? I believe there is some example in the manual. Or do you want to multiply numbers by 100 and append "%"? This should not be too difficult using some numeric postprocessor, but there is no style preset. –  Christian Feuersänger Aug 2 '12 at 14:14
    
@ChristianFeuersänger Yes, I was thinking of the latter: multiply by 100 and append "%". However, the former would be acceptable as well. Unfortunately I can't find the example in the manual... I did a search for "\%" since a search for % brings up too many results.. also searched for "percent". Do you happen to know what section of the manual it is in? –  Trevor Aug 2 '12 at 16:42
    
See my edited answer. Note that the manual contains an example with \EUR, not with \% (sorry). –  Christian Feuersänger Aug 2 '12 at 17:50
    
I posted a separate question and wrote my answer to that thread to simplify searches for that topic. Please see if tex.stackexchange.com/questions/65760/… fulfills your needs. –  Christian Feuersänger Aug 3 '12 at 19:30
    
Perfect. Thank you! –  Trevor Aug 3 '12 at 22:08
add comment

2 Answers

up vote 11 down vote accepted

Pgfplotstable has styles like every row no <index> and some other styles as well.

However, these styles are applied quite late in the processing: the content is already fixed at that stage.

I accept this as a feature request.

However, there is a simple way to enable such a style: the styles named every row <rowindex> column <colindex>. These styles allow changes to the content generation, in particular, they respect changes to the number format.

You can group a sequence of such styles to change all values of a specific column easily using

\documentclass{article}

\usepackage{pgfplotstable}

\begin{document}

\pgfplotstableset{
    % #1 = row index
    % #2 = row style keys
    row style/.style 2 args={
        every row #1 column 0/.style={#2},
        every row #1 column 1/.style={#2},
        every row #1 column 2/.style={#2},
        every row #1 column 3/.style={#2},
        every row #1 column 4/.style={#2},
        every row #1 column 5/.style={#2},
        every row #1 column 6/.style={#2},
        every row #1 column 7/.style={#2},
        every row #1 column 8/.style={#2},
        every row #1 column 9/.style={#2},
        every row #1 column 10/.style={#2},
    }
}

\pgfplotstabletypeset[
    row style={3}{sci},
]{
    a b
    0 0
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 10
}

\end{document}

EDIT: concerning your second question: you wanted to format percentages (i.e. to multiply with 100 and to append '%'):

enter image description here

\documentclass{standalone}

\usepackage{pgfplotstable}

\begin{document}

\pgfplotstabletypeset[
    columns/A/.style={
        column type=r,
        preproc/expr={100*##1},
        postproc cell content/.append style={
            /pgfplots/table/@cell content/.add={}{\%},
        },
        fixed,
        fixed zerofill,
    },
]
{
 A
 0.01
 1
 0.1234
 0.5
}

\end{document}
share|improve this answer
    
This works beautifully! Thanks! Now if I could only find the way to append "%" like you mentioned I'd be all set... –  Trevor Aug 2 '12 at 16:52
    
Great! Thank you for the edits! –  Trevor Aug 2 '12 at 19:24
    
Hmm... actually, your edit assigns the % symbol to a whole column, but I actually need it for a row... Is there a way to incorporate the /.add={}{\%} into the row style arguments? Maybe I'm being dense, but I can't see how that's done... –  Trevor Aug 3 '12 at 0:12
    
Ok, I figured out a way to incorporate the /.add={}{\%} into the row style arguments. However, since I'm using dec sep align on the rows, pgfplots creates additional rows. The problem is that the new code is adding "%" signs in both of the columns. See picture I attached in the OP. I tried removing the code for every other column number, but I guess since that happens before the dec sep align the columns haven't been split yet so it just removes the "%" for the entire column –  Trevor Aug 3 '12 at 0:21
add comment

For those who'd like to know my solution for applying the percentages format to a row instead of a column, just input the code from Christian's answer in Pgfplotstable: how can I add percent signs (and respect dec sep align)? as the second argument {#2}:

\pgfplotstableset{
    % #1 = row index
    % #2 = row style keys
    row style/.style 2 args={
        every row #1 column 0/.style={#2},
        every row #1 column 1/.style={#2},
        every row #1 column 2/.style={#2},
        every row #1 column 3/.style={#2},
        every row #1 column 4/.style={#2},
        every row #1 column 5/.style={#2},
        every row #1 column 6/.style={#2},
        every row #1 column 7/.style={#2},
        every row #1 column 8/.style={#2},
        every row #1 column 9/.style={#2},
        every row #1 column 10/.style={#2},
    }
}

\pgfplotstableread[col sep=comma]{data.csv}\datatable
\pgfplotstabletypeset[
    row style={(the row number with percentage data)}{precision=2,postproc cell content/.append code={
                \ifnum1=\pgfplotstablepartno
                    \pgfkeysalso{@cell content/.add={}{\%}}%
                \fi
    }}
    ]{\datatable}
share|improve this answer
add comment

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.