8

I am having a real hard time trying to format a simple numeric table with PGFPlotsTable. I have tried tons of combinations of TeX.SO solutions, I just cannot get any working result.

The table looks like the following:

0.xy;0.00;0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09
0.00;-1.1;-0.5;-0.326;-0.3;-0.2;-0.1;0.0;0.0;0.0;0.1
0.10;0.1;0.1;0.1;0.2;0.2;0.2;0.2;0.2;0.2;0.2
0.20;0.2;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3
0.30;0.3;0.3;0.3;0.3;0.4;0.4;0.4;0.4;0.4;0.4
0.40;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4
0.50;0.4;0.4;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.60;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.70;0.5;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6
0.80;0.6;0.7;0.7;0.7;0.7;0.7;0.7;0.7;0.8;0.8
0.90;0.8;0.8;0.9;0.9;1.0;1.1;1.2;1.4;1.7;1.9

This is a 11x11 matrix (a percentiles table). [Updated: The first cell is empty] The first cell is a label, and all others cells are guaranteed to be numeric. I would like to have the first row and the first column in bold font series and using the following style: fixed, zerofill, precision=2. The other numbers must be left as this.

As far as I have understood the PGFPlotsTable mechanism:

  • styles are defined by columns and can be altered cell by cell;
  • header/row styles does not care about fixed and precision keys.

Are those statements right?

I also had strange behaviour modification when I fill the first cell with text or with a number, then my styles apply differently. I have tried to treat the first line as a header or as a simple row.

Is what I ask possible? If so, how do I achieve it?

Update 1: Here you will find my MNWE (Minimal Non Working Example), this is the best I could achieve and it does not do the trick

\pgfplotstabletypeset[
    col sep=semicolon,1000 sep={},font=\footnotesize,dec sep align,fonts by sign={}{\color{red}},
    every head row/.style={output empty row},
    every first row/.style={fixed,zerofill,precision=2},
    every first column/.style={fixed,zerofill,precision=2}
]{p.csv}

I do not understand why my first row is in scientific representation. And I could not set bold format neither for the column, nor for the row.

Update 2: Going deeper, I have tried many things and I am just surprised how a apparently simple formatting can be so tricky. I finally found how to access a single cell, but I cannot get a proper result when trying to format it.

\pgfplotstabletypeset[col sep=semicolon,
    header=false,col sep=semicolon,1000 sep={},font=\footnotesize,
    fixed,dec sep align,fonts by sign={}{\color{red}},
    every head row/.style={output empty row},
    every first row/.style={before row=\toprule},
    every last row/.style={after row=\bottomrule},
    columns/0/.style={zerofill, precision=2},
    every row 0 column 1/.style={zerofill, precision=2},
    every row 6 column 1/.style={postproc cell content/.append style={@cell content/.add={x}{y}}}
]{p.csv}

This MNWE outputs xx0yy.xx4yy to the cell(6,1). It looks like the function add is called twice on the integer part and then twice on the decimal part of my number (WTH, this explains why my outputs are so difficult to understand). Is it a bug? If not, how this behaviour can be explained?

It is impossible to make it bold using /.add{\bf}{} as stated in the manual, but it is if I add column type=r at the very top level (which leads to right aligned columns instead of decimal aligned columns).

I have used content={\textbf{##1}} instead of /.add{\bf}{} (removing or not the append keyword) it outputs an unexpected 0<space> before the real cell content (looks like a phantom of the integer part).

I have tried to remove style options, it does not help. It is the third time I read the 70-pages manual, and I just cannot make it work. What am I missing? How could this be so difficult?

Update 3: Still working on my table, here a MWE that achieve most of my goals.

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}[!ht]
\centering
\pgfplotstabletypeset[
col sep=semicolon,
header=has colnames,
columns/0.xy/.style={column name={},column type=r,string type,postproc cell content/.append style={@cell content={\textbf{##1}}}},
every head row/.style={before row=\toprule},
every last row/.style={after row=\bottomrule},
columns/0.00/.style={dec sep align},
columns/0.01/.style={dec sep align},
columns/0.02/.style={dec sep align},
columns/0.03/.style={dec sep align},
columns/0.04/.style={dec sep align},
columns/0.05/.style={dec sep align},
columns/0.06/.style={dec sep align},
columns/0.07/.style={dec sep align},
columns/0.08/.style={dec sep align},
columns/0.09/.style={dec sep align}
]{./media/data2.csv}
\end{table}
\end{document}

I cannot format header in bold, and alignment of header is somehow filthy. When a tried to set dec sep align at the table style level and reset styles at the first column level, I get compilation error, so I have to impose styles column by column.

How do I format header in bold? How do I impose numeric style to every columns except the first which is string type?

I think I have showed some effort to solve my problem. I just get no answer to my post even after starting a bounty. Is my request unfeasible?

  • Please help us help you and add a minimal working example (MWE). – Henri Menke Nov 3 '15 at 16:25
  • I am working on it, I will post it in a few minutes – jlandercy Nov 3 '15 at 16:26
  • I have added a MNWE – jlandercy Nov 3 '15 at 16:40
  • Is there any way to create a row of column names in the source, or do they have to be added retroactively? – John Kormylo Nov 3 '15 at 22:04
  • @JohnKormylo Yes I may automatically add a header to data, will this help me solve my issue? – jlandercy Nov 4 '15 at 8:48
11
+50

I see that you have suffered a great deal of frustration. And I am the correct person to receive it as I wrote pgfplotstable, so let me try to accept and ease some of the frustration, and try to help you with it.

Since you stated lots of questions, probably originating in your frustration, I would like to address them:

  1. Are styles defined by columns and can be altered cell by cell?

    Hm... partially: the vision is to configure a common appearance for an entire column. Cell-by-cell adoptions are almost not supported, except for some relatively crude mechanisms. This is one of the sources of frustration, I guess.

  2. header/row styles does not care about fixed and precision keys, right?

    Yes, correct, as row-based "styles allow to configure the final table code after any cell contents have been assigned."

    Consequently, row-based styles do not even allow you to configure "use boldface for my cells". They operate on the entire row, no longer on cells.

  3. Is what I ask possible? If so, how do I achieve it?

    Yes, see below.

  4. ..."And I could not set bold format"

    bold face format is something that beats me whenever I work with numerical tables... and that is probably the reason why it beats you as well (namely because I did still did not offer suitable styles).

    The boldface styles for math fonts seem to require the following items

    • they need to be given inside of the math mode, i.e. inside of $ and $ which makes it difficult to handle within pgfplotstable
    • using \bf is relatively simple, but AFAIK it is discouraged
    • \mathbf{...} also requires bracing constructs which is also not really simple to add around existing values (or perhaps pgfplotstable is not really helping here).

    I should think about better solutions here eventually.

  5. [...] It looks like the function add is called twice on the integer part and then twice on the decimal part of my number (WTH, this explains why my outputs are so difficult to understand). Is it a bug?

    I believe it is a bug, yes. I can reproduce lots of problems with the decimal part splitting. In fact, my solution below excludes dec sep align (and also excludes what you wanted to address with it)

Here is what I came up with. Your table has the requirement that it uses column names which should be formatted as numbers on their own (something which needs adoptions as pgfplotstable assumes plain column names).

As mentioned above, I also failed to integrate dec sep align, something that I should look into eventually. Apparently, it fails to split columns correctly somewhere.

\documentclass{standalone}
\usepackage{array}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[
    col sep=semicolon,
    font=\footnotesize,
    fixed,precision=2,
    %dec sep align,
    fonts by sign={}{\color{red}},
    every first column/.style={
        fixed zerofill, precision=2,
        postproc cell content/.append style={
            @cell content/.add={$\bf}{$}%
        }%
    },
    assign column name/.style={%
        /pgfplots/table/column name={$\bf \pgfmathprintnumber[fixed zerofill,precision=2]{#1}$}%
    },%
    columns/0.xy/.style={%
        assign column name/.code=,
        column name=\textbf{ABC},
    },
    %debug,
]{
0.xy;0.00;0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09
0.00;-1.1;-0.5;-0.326;-0.3;-0.2;-0.1;0.0;0.0;0.0;0.1
0.10;0.1;0.1;0.1;0.2;0.2;0.2;0.2;0.2;0.2;0.2
0.20;0.2;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3
0.30;0.3;0.3;0.3;0.3;0.4;0.4;0.4;0.4;0.4;0.4
0.40;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4
0.50;0.4;0.4;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.60;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.70;0.5;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6
0.80;0.6;0.7;0.7;0.7;0.7;0.7;0.7;0.7;0.8;0.8
0.90;0.8;0.8;0.9;0.9;1.0;1.1;1.2;1.4;1.7;1.9
};
\end{document}

enter image description here

My personal recommendation would be to use fixed zerofill for all columns instead of dec sep align; it results in

enter image description here

Perhaps you are also interested to see your example with row/col rules, feel free to use or to ignore it:

\documentclass{standalone}
\usepackage{array}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[
    col sep=semicolon,
    font=\footnotesize,
    fixed, precision=2,
    fixed zerofill,
    %dec sep align,
    fonts by sign={}{\color{red}},
    every first column/.style={
        fixed,fixed zerofill, precision=2,
        postproc cell content/.append style={
            %@cell content/.add={$\bf}{$}%
        }%
    },
    assign column name/.style={%
    %   /pgfplots/table/column name={$\pgfmathprintnumber[fixed,fixed zerofill,precision=2]{#1}$}%
    },%
    columns/0.xy/.style={%
        assign column name/.code=,
        column name=ABC,
        column type=c|,
    },
    every head row/.style={
        before row=\toprule,after row=\midrule},
    every last row/.style={
        after row=\bottomrule},
    %debug,
]{
0.xy;0.00;0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09
0.00;-1.1;-0.5;-0.326;-0.3;-0.2;-0.1;0.0;0.0;0.0;0.1
0.10;0.1;0.1;0.1;0.2;0.2;0.2;0.2;0.2;0.2;0.2
0.20;0.2;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3;0.3
0.30;0.3;0.3;0.3;0.3;0.4;0.4;0.4;0.4;0.4;0.4
0.40;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4;0.4
0.50;0.4;0.4;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.60;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5;0.5
0.70;0.5;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6;0.6
0.80;0.6;0.7;0.7;0.7;0.7;0.7;0.7;0.7;0.8;0.8
0.90;0.8;0.8;0.9;0.9;1.0;1.1;1.2;1.4;1.7;1.9
};
\end{document}

enter image description here

  1. I think I have showed some effort to solve my problem. I just get no answer to my post even after starting a bounty. Is my request unfeasible?

    When I wrote pgfplotstable, I had relatively special requirements in mind for which I tailored it. In addition, I managed to extend the use-cases to get a relatively powerful tool. I fear that you encountered a use-case which has no natural fit into the offered styling/customization rules. So, perhaps we have to state: "it is unfeasible with pgfplotstable unless one has lots of time, expert knowledge, and love for a tool which does not fit right-away".

  • 1
    Some more detail: dec sep align apparently does likes neither column type nor assign column name. In addition, it does not work if the column name is a number which should be aligned at its decimal separator as well. Seems as if this is the main cause of problems here. – Christian Feuersänger Nov 8 '15 at 13:11
  • 1
    Hope the edit was fine. \bf is discouraged, but there is of course \bfseries which is a replacement. – Torbjørn T. Nov 8 '15 at 13:55
  • 1
    @ChristianFeuersänger, Thank you for answering. As I can see in your answer I was far away. Nice package anyway, it is really handy and render nice, as long as you understand the deep inside mechanisms. After tons of testes, you helped my to understand. – jlandercy Nov 8 '15 at 14:19
  • @TorbjørnT. Apparently, \bf can be used inside of math mode whereas \bfseries cannot. And \mathbf is not a toggle but requires an argument. Is there another alternative for \bf? I believe I did some research some time ago and found no suitable replacement (for math mode, of course) – Christian Feuersänger Nov 8 '15 at 16:53
  • Ah, sorry, didn't consider math mode. I see there is a \boldmath switch (How can I get bold math symbols?), but you probably found that one. – Torbjørn T. Nov 8 '15 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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