有没有简单的方法可以改变 pgfplotstable 的列顺序?

有没有简单的方法可以改变 pgfplotstable 的列顺序?

我知道重新排列 pgfplotstable 中的数据但我希望找到一种一次性解决方案,它不会将表分散到那么多命令中,而是包含在其中\pgfplotstabletypeset

以下是我不太简单的例子(抱歉,但我想让事情保持合理但可读......):

\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}

表格示例

显然我在这里搞砸了,需要将数字列移到文本列后面,因此从 [1, 2, 3] 移到 [2, 1, 3]。如果不将整个内容作为 CSV 文件读入电子表格,然后在那里执行基于列的操作,最简单的方法是什么?

答案1

可以通过键改变列顺序columns={column2,column1,...}

\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}

在此处输入图片描述

相关内容