
各行から最初の列を減算して、別の列から新しい列を作成しようとしています。次に、相対的な差を持つ別の列を作成します。
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
TotalDistance
35089
35182
35410
35523
35694
35789
35895
35984
36006
36068
}{\mytable}
\pgfplotstabletypeset[
columns={TotalDistance,LocalDistance},
create on use/LocalDistance/.style={
create col/expr={\thisrow{TotalDistance} - 35089},
},
create on use/DifferenceDistance/.style={
create col/expr={\thisrow{LocalDistance} - \prevrow{LocalDistance}},
},
]{\mytable}
\end{document}
私の目標は以下のとおりです:
TD | LD | DD
------+-----+----
35089 | 0 | 0
35182 | 93 | 93
35410 | 321 | 228
35523 | 434 | 113
35694 | 605 | 171
35789 | 700 | 95
35895 | 806 | 106
35984 | 895 | 89
36006 | 917 | 22
36068 | 979 | 62
これまでの問題は次のとおりです。
- ハードコードを避け
35089
、代わりに最初のセルから読み取るにはどうすればよいですか? - エラーが発生します不明な関数 `LocalDistance__column_not_found'列 DifferenceDistance をタイプセットしようとすると、列 LocalDistance は問題なく作成されるにもかかわらず、
答え1
最初のセルの値は で読み取ることができます
\pgfplotstablegetelem{<row>}{<col>}\of\mytable
。戻り値は に書き込まれます\pgfplotsretval
。提案された打楽器
\pgfplotstablecreatecol
の代わりにを使用して\pgfplotstabletypeset
テーブルに列を追加する例を次に示します。
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
TotalDistance
35089
35182
35410
35523
35694
35789
35895
35984
36006
36068
}{\mytable}
% read the first cell value -> \pgfplotsretval
\pgfplotstablegetelem{0}{TotalDistance}\of\mytable
% add column LocalDistance
\pgfplotstablecreatecol
[expr={\thisrow{TotalDistance} - \pgfplotsretval}]
{LocalDistance}{\mytable}
% add column DifferenceDistance
\pgfplotstablecreatecol
[expr={\thisrow{LocalDistance} - \prevrow{LocalDistance}}]
{DifferenceDistance}{\mytable}
% typeset the table
\pgfplotstabletypeset
[columns={TotalDistance,LocalDistance,DifferenceDistance}]
{\mytable}
\end{document}