4

Trying to transpose the table like in my MWE. The result is quit nice, but contains first extra row, I'd like to exclude it. Read pgf manual, used skip rows between index={}{}, but without effect. How to delete this first extra-row (colnames etc...)?

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

\pgfplotstableread{
N    Ans
1   -36
2    33
3   -52
4   -22
5    33
6    38
7    48
8  -100
}\mytable

\pgfplotstabletranspose[string type]\mytablenew{\mytable}

\pgfplotstabletypeset[string type]{\mytablenew}
\end{document}
Rico
  • 6,097
Olga K
  • 981
  • 2
    Does the solution in Pgfplotstable without headings row help you? Just tested it and it should work. – Alenanno Jan 20 '16 at 13:09
  • Change your \pgfplotstabletypeset[string type]{\mytablenew} to \pgfplotstabletypeset[string type, every head row/.style={ output empty row, }]{\mytablenew} – Rico Jan 20 '16 at 13:11
  • @Rico That's exactly what the link above says. – Alenanno Jan 20 '16 at 13:11
  • @Alenanno nice :) would be pretty scary if this questions hadn't come up already :) – Rico Jan 20 '16 at 13:12
  • Since the OP has solved the issue, I'll vote to close as a duplicate. – Alenanno Jan 20 '16 at 13:16
  • 4
    You could also use \pgfplotstabletranspose[string type, colnames from=N, input colnames to=N]\mytablenew{\mytable} to avoid generating that extra row. colnames from=N tells PGFPlots to use an existing column for the column names, input colnames to=N tells it to use N in the first cell. – Jake Jan 20 '16 at 13:16
  • @Jake Nice! Shouldn't the extra row not be generated by default though? Or it is supposed to be created for some reason? – Alenanno Jan 20 '16 at 13:17
  • 1
    @Alenanno: PGFPlotstable generates column names by default so you have a chance to reference the columns easily after the transposition. Otherwise you might have name clashes in the new column names – Jake Jan 20 '16 at 13:18
  • @Alennano surely you can close. I didn't see the topic you mentioned. – Olga K Jan 20 '16 at 13:18
  • 1
    Simply hiding the header row is not an ideal solution, in my opinion, since that stops you from formatting the first row properly. – Jake Jan 20 '16 at 13:19
  • @OlgaK Don't worry, it often happens that some questions come up again. :D – Alenanno Jan 20 '16 at 13:19
  • @Jake If you think there's a better solution, you could answer it! :P – Alenanno Jan 20 '16 at 13:20
  • 1
    @Alenanno: I was trying, but it got closed too quickly. I've voted to reopen. – Jake Jan 20 '16 at 13:25

1 Answers1

6

You can either hide the newly created row when you're printing the transposed table with the approach from Pgfplotstable without headings row (as suggested by Alenanno in the comments).

However, that way you can't use formatting options like every head row, which are especially useful when using booktabs, since you're not printing the head row.

You can stop the new row from being generated by setting

    colnames from=N, input colnames to=N

in the \pgfplotstabletranspose options. The first option tells PGFPlotstable to use an existing column (in this case N) for the column names in the transposed table, the second option tells PGFPlotstable to use N as the header for the original column names.

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

\pgfplotstableread{
N    Ans
1   -36
2    33
3   -52
4   -22
5    33
6    38
7    48
8  -100
}\mytable

\pgfplotstabletranspose[string type,
    colnames from=N,
    input colnames to=N
]\mytablenew{\mytable}

\pgfplotstabletypeset[
    every head row/.style={
        before row=\toprule,
        after row=\midrule
    },
    every last row/.style={
        after row=\bottomrule
    },
string type]{\mytablenew}
\end{document}
Jake
  • 232,450
  • For now I have 1 more question, how to reduce the space between columns in prevoius example? – Olga K Feb 14 '16 at 10:58