2

Here is a MWE:

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}

Here is the multiplication table in roman numeral. 

\pgfplotstabletypeset[string type]{
  i   ii   iii
  ii  iv   vi 
  iii vi   ix 
}

I would love it to include the column headers:
\begin{quote}
 1 \quad 2 \quad 3 
\end{quote}
and the same row headers. 

But, I have no idea how to achieve this efficiently with \verb|pgfplotstable|.
I do not want the solution to rely on the number being consecutive; 
ideally, it would take a list such as 
\begin{quote}
\begin{verbatim}
  \def\ROMANS{I,II,III}
\end{verbatim}
\end{quote}
\end{document}

Sample Output

2
  • 1
    The column headers are easy to fix header=false,display columns/0/.style={column name={I}}, for the rows it needs some more work.
    – percusse
    Jan 28, 2014 at 16:55
  • I am aware of it, but it is quite tedious if you are to produce, e.g., the multiplication table of numbers up to twenty...
    – Yossi Gil
    Jan 28, 2014 at 18:42

1 Answer 1

2

I hope I understood your question so that it boils down to have a key that takes a list of column names and assigns it to the single columns:

\pgfplotstable[display column names={A,B,C}]{...}

If so, the following example does this. It defines a key that takes a list of column names. Note, that it contains code that is taken from another tex.sx answer from @Villemoes and I know to less about tex to say if it is correct or will work in every case. So I cannot give any warranty:

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

% taken from one comment of Villemoes in
% https://tex.stackexchange.com/a/15263/3061
\def\pgfglobalkeys#1{\begingroup \ifnum\the\globaldefs>0\relax \else \globaldefs=1\fi \pgfkeys{#1}\endgroup}

% define the new key
\pgfplotstableset{display column names/.code={
        \foreach[count=\n from 0] \x in {#1} {
            \pgfglobalkeys{/pgfplots/table/display columns/\n/.estyle={column name=\x}}
        }
    }
}

\begin{document}

\pgfplotstabletypeset[string type, header=false, display column names={A,B,C}]{ %
  i   ii   iii
  ii  iv   vi 
  iii vi   ix 
}

\end{document}

The key code of column names is straight forward and easy to understand. It will loop over the given list using a foreach loop and sets the columns name. The problem is that the foreach body is encapsulated in a group so that any change to a macro, counter or key is local. So after we quit the loop all keys are reset. Therefor I took the \pgfglobalkeys from Villemoes. And then it works :).

enter image description here

5
  • 1
    indeed you are missing the row headers. another convenience is the /.list handler to repeat key settings. you can find it in the manual.
    – percusse
    Jan 29, 2014 at 0:23
  • @percusse, that was also my first idea, but with the /.list handler you do not have the current loop count which you need.
    – quinmars
    Jan 29, 2014 at 0:32
  • and indeed i forgot the row header ..., but they are a different story. But it's time to sleep.
    – quinmars
    Jan 29, 2014 at 0:34
  • Oh time to dig up old answers then. I did something like that way back...
    – percusse
    Jan 29, 2014 at 13:09
  • Is this what you mean? tex.stackexchange.com/questions/69034/…
    – Yossi Gil
    Jan 29, 2014 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .