3

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}
  • 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
  • 3
    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
  • 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
  • 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
  • 1
    @Alenanno: I was trying, but it got closed too quickly. I've voted to reopen. – Jake Jan 20 '16 at 13:25
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}
  • 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

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.