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.

I would like to use the dec sep align feature of pgfplotstable while having certain cells containing text. I tried this:

\documentclass{article}

\usepackage{pgfplotstable}
\usepackage{booktabs}

\begin{document}

\pgfplotstabletypeset[%
col sep=&, row sep=\\,header=false,
every head row/.style={before row={\toprule}, after row={\midrule}},
every last row/.style={after row=\bottomrule},
display columns/0/.style={column name={A}, string type, column type={l}},
display columns/1/.style={column name={B}, dec sep align={l}},
display columns/2/.style={column name={C}, dec sep align={l}},
every row 2  column 1/.style={string type},
every row 3  column 1/.style={string type},
]
{%
  Xyzzy ! &     208.5  &   42.01  \\
  Nothing &    7.91  &   42.1  \\
  Happens &     --   &   200.2 \\
  \ldots  &      z   &  4.54 \\
}
\end{document}

But the result turned out to be this :

Buggy table

Do you know why the separations between the text cell and the next get swallowed? How could I correct this behaviour? I would welcome any suggestion that allows to produce a correctly spaced tables (with alignment on the decimal separator), even if I must part with pgfplotable for that particular one. I would rather stick to it though so that I can keep most of my tables as is.

I exised my previous edit to make another question (see here) for fear it would be too confusing to have them together

share|improve this question
    
I don't think this should be corrected as you are using an option that expects only numbers. But interesting thing is that this doesn't give a pgfmath NaN error but instead steals content from the remaining columns until it finds a number. If I make a space separated table I get directly Could not parse input -- as a floating number ... error. –  percusse Sep 23 '12 at 10:22
    
When I do not use the 'dec sep align' similar setup work well. I thought that every row 2 column 1/.style={string type}, would be sufficient to enable text input. –  Alfred M. Sep 23 '12 at 11:47
    
Interestingly even if I replace the two non-numbers (--, and z) I still see the bizarre behavior. –  Peter Grill Sep 26 '12 at 7:37
    
I guess the problem comes from the every row 2 column 1/.style={string type} specification and not form the contents being indeed non numbers. I suppose that when one replace them by numbers, they are actually treated as letter numbers. –  Alfred M. Sep 26 '12 at 7:45

1 Answer 1

up vote 5 down vote accepted
+50

The dec sep align splits its column into two sub-columns (one each for the number part before and after the decimal separator). Normally, pgfplotstable checks whether the number in a cell has a decimal separator, and if it doesn't, an empty cell is added as a placeholder for the decimal part. When you set string type for a single cell, that check doesn't take place, and the placeholder cell (which is just an &) is not added. pgfplotstable still assumes the dec sep align column to always contain two cells, though, so the first cell of the next column is used instead of the placeholder cell.

So, we'll have to add an empty placeholder cell in manually. We can't just put a & after the string in the table, because that would throw the column count off, so we'll have to be a bit more sneaky: There's a postproc cell content key, which allows us to add stuff to a cell after it's been processed. Just adding a & here wouldn't work either, though, because that would add two &s (because, as mentioned above, pgfplotstable still assumes that there are two cells in a dec sep align column, and the postproc cell content key is executed for both of these cells). Luckily, there's a macro called \pgfplotstablepartno which contains the index of the current "sub-cell", it's 0 for the part before and 1 for the part after the decimal separator. This can be used in an \ifnum to only add one &.

Wrapping that in a new style, we get

\pgfkeys{
    /pgfplots/table/string type in dec sep align/.style={
        string type,
        postproc cell content/.code={%
            \ifnum\pgfplotstablepartno=0%
                \pgfkeys{/pgfplots/table/@cell content/.add={}{&}}
            \fi
        }%
    }
}

which allows us to set a single cell in a dec sep align column to string type in dec sep align. That results in the desired output:

\documentclass{article}

\usepackage{pgfplotstable}
\usepackage{booktabs}



\begin{document}

\pgfkeys{
    /pgfplots/table/string type in dec sep align/.style={
        string type,
        postproc cell content/.code={%
            \ifnum\pgfplotstablepartno=0%
                \pgfkeys{/pgfplots/table/@cell content/.add={}{&}}
            \fi
        }%
    }
}

\pgfplotstabletypeset[%
col sep=&, row sep=\\,header=false,
every head row/.style={before row={\toprule}, after row={\midrule}},
every last row/.style={after row=\bottomrule},
display columns/0/.style={column name={A}, string type, column type={l}},
display columns/1/.style={column name={B}, dec sep align},
display columns/2/.style={column name={C}, dec sep align},
every row 2  column 1/.style={string type in dec sep align},
every row 3  column 1/.style={string type in dec sep align},
]
{%
  Xyzzy ! &     208.5  &   42.01  \\
  Nothing &    7.91  &   42.1  \\
  Happens &     --  &   200.2 \\
  \ldots  &      z   &  4.54 \\
}
\end{document}
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.