假设一个简单的例子csvsimple包裹。
\documentclass{standalone}
\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}
\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}
\begin{document}
% COUNT THE ROWS
\csvreader{input.csv}{}{}%
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
\csvreader[tabular=|c|l|c|c|,
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
%{\FPeval{\result}{\thecsvrow+50} & \textit{\foo} & \bar & \baz} % NOT WORKING: simply swallows the line numbers
{\thecsvrow & \textit{\foo} & \bar & \baz}
\end{document}
我希望行号(由 定义\thecsvrow
)从 51 开始,而不是从 1 开始。因此,行应该显示数字51,52和53在第一列。
我理解建议的(但注释掉的)代码行不可能起作用,因为需要通过再次调用来调用所需的数字\result
。尽管如此,我想不出解决这个问题的方法,希望论坛中的某个人能想到。
答案1
使用 TeX 原生整数算法进行更改:\the\numexpr50+\thecsvrow\relax
。
\documentclass{standalone}
\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}
\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}
\begin{document}
% COUNT THE ROWS
\csvreader{input.csv}{}{}%
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
\csvreader[tabular=|c|l|c|c|,
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
%{\FPeval{\result}{\thecsvrow+50} & \textit{\foo} & \bar & \baz} % NOT WORKING: simply swallows the line numbers
{\the\numexpr50+\thecsvrow\relax & \textit{\foo} & \bar & \baz}
\end{document}
如果您想要最初尝试的方法,则只需在单元格末尾fp
添加即可。这是因为进行计算并将其存储在中,但不输出任何内容。但是,在该状态下,输出是浮点数,具有像这样的条目。因此,您还需要ate 才能获得与上面相同的输出:\result
\FPeval{\result}{\thecsvrow+50}
\result
51.0000000000000
\FPtrunc
\documentclass{standalone}
\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}
\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}
\begin{document}
% COUNT THE ROWS
\csvreader{input.csv}{}{}%
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
\csvreader[tabular=|c|l|c|c|,
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
{\FPeval{\result}{\thecsvrow+50}\FPtrunc\result{\result}{0}\result & \textit{\foo} & \bar & \baz} % NOT WORKING: simply swallows the line numbers
%{\the\numexpr50+\thecsvrow\relax & \textit{\foo} & \bar & \baz}
\end{document}