I wrote a table that turned out to be too wide. So I have to turn it sideways for it to fit a typical journal paper. Is there a way I can avoid typing it all over again?!
Asked
Active
Viewed 3,125 times
5
-
Do you mean you want to rotate the whole table or that you want to make all the rows into columns (like transpose in Excel)? – Thruston Aug 25 '17 at 20:14
-
1@Thruston I want to transpose the matrix. – Maesumi Aug 25 '17 at 20:19
-
2pgfplotstable can create a transpose. On page 4 it shows how to fake a tabular environment. On page 62 it shows how to transpose. – John Kormylo Aug 25 '17 at 22:48
-
1If you use Emacs’ org-mode to prepare your tables, org-mode can transpose tables: http://pragmaticemacs.com/emacs/transpose-a-table-in-org-mode/ – Thérèse Aug 26 '17 at 00:32
-
1See if this could be useful: https://tex.stackexchange.com/q/283081/101651 – CarLaTeX Aug 26 '17 at 07:07
-
2I wrote a TeX-aware table filter for use with Vim that does table transposition: select the rows and do "Table xp" for a transpose. If you post your table here, I could post a transposed version as an answer. – Thruston Aug 26 '17 at 17:33
-
@Thruston Thanks, I ended up typing it again and editing it quite a bit to make it smaller. But It is good to know these options are available for a large table. – Maesumi Aug 27 '17 at 00:04
-
1https://tex.stackexchange.com/q/75793 ? – Thérèse Sep 02 '17 at 02:33
1 Answers
2
Like John Kormylo said, pgfplotstable can be a convenient way to do this.
\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
{Header 1} A B C D E
{Header 2} 1 2 3 4 5
{Header 3} 10 11 12 13 14
}\tablesource
\pgfplotstabletranspose[string type,
colnames from={Header 1},
input colnames to={Header 1}
]\tabletransp{\tablesource}
\begin{center}
Table Source:
\pgfplotstabletypeset[string type,
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
after row=\midrule
]{\tablesource}
\vspace{8mm}
Table transpose:
\pgfplotstabletypeset[string type,
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
after row=\midrule
]{\tabletransp}
\end{center}
\end{document}
I'm not a expert, but in my test's I understand that's need to stay alert about spaces.
In \pgfplotstableread you will enter you source table. Into the final of this command, you will name this source; in this case is \tablesource.
In \pgfplotstabletranspose you will finish with tha name of transposed table; \tabletransp.
The command \pgfplotstabletypeset will call what you put into brackets.
Jean Pimenta
- 617
- 5
- 9
