Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am aware of Rearrange data in pgfplotstable but I was hoping for a kind of one-pass solution that doesn't spread the table over so many commands but is rather self-contained within \pgfplotstabletypeset.

So here is my not-so-minimal example (sorry but I wanted to keep the thing plausible but readable ...):

\documentclass{standalone}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{ragged2e}
\definecolor{cellshade}{rgb}{0.77, 0.82, 0.93}
\definecolor{lightcellshade}{rgb}{0.89, 0.91, 0.97}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}m{#1}}
\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    column type={C{.24\linewidth}},
    columns/Text/.style={reset styles,string type,column type={R{.5\linewidth}}},
    columns/Number/.style={reset styles,string type,column type={C{.1\linewidth}}},
    every head row/.style={before row={\rowcolor{cellshade}}},
    every odd row/.style={before row={\rowcolor{lightcellshade}}},
    /pgf/number format/fixed,
    /pgf/number format/precision=2,
]{
Number,Text,Value
1,Lorem ipsum dolor sit amet,0.94178749278214
2,consetetur sadipscing elitr,0.76901823992132
3,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,0.65253718698821
4,sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,0.18096270994776
5,no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,0.29164374147955
6,consetetur sadipscing elitr,0.39600362303508
7,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,0.60941476968239
8,sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,0.12296095617755
9,no sea takimata sanctus est Lorem ipsum dolor sit amet.,0.70795563336377
}
\end{document}

table example

Obviously I screwed up here and need to move the Number column after the Text column, so from [1, 2, 3] to [2, 1, 3]. What's the easiest way of doing that without reading the whole thing as a CSV file into a spreadsheet and then performing column-based operations there?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

Column ordering can be altered via columns={column2,column1,...} key.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{ragged2e}
\definecolor{cellshade}{rgb}{0.77, 0.82, 0.93}
\definecolor{lightcellshade}{rgb}{0.89, 0.91, 0.97}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}m{#1}}
\begin{document}
\pgfplotstabletypeset[
    columns={Text,Number,Value},
    col sep=comma,
    column type={C{.24\linewidth}},
    columns/Text/.style={reset styles,string type,column type={R{.5\linewidth}}},
    columns/Number/.style={reset styles,string type,column type={C{.1\linewidth}}},
    every head row/.style={before row={\rowcolor{cellshade}}},
    every odd row/.style={before row={\rowcolor{lightcellshade}}},
    /pgf/number format/fixed,
    /pgf/number format/precision=2,
]{
Number,Text,Value
1,Lorem ipsum dolor sit amet,0.94178749278214
2,consetetur sadipscing elitr,0.76901823992132
3,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,0.65253718698821
4,sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,0.18096270994776
5,no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,0.29164374147955
6,consetetur sadipscing elitr,0.39600362303508
7,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,0.60941476968239
8,sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,0.12296095617755
9,no sea takimata sanctus est Lorem ipsum dolor sit amet.,0.70795563336377
}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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