我有一个以秒为单位的时间文件,我想在 pgfplotstabletypeset 中创建一个表达式,将秒转换为 2h35m40s。我只知道如何转换为小时、分钟和秒,但没有将它们连接起来。我该怎么做?
\pgfplotstabletypeset[col sep=comma,
columns={Tamanho,UiSCSI},
columns/Tamanho/.style={
column name={\textbf{Tamanho}},
precision=4,
column type=l,
preproc/expr={##1/1000},
postproc cell content/.append code={
\pgfkeysalso{@cell content/.add={}{ GB}}%
},
},
columns/UiSCSI/.style={
column name={\textbf{UiSCSI}},
fixed,fixed zerofill,precision=0,
preproc/expr={{##1/3600}},
postproc cell content/.append code={
\pgfkeysalso{@cell content/.add={}{h}}%
},
column type=r,
},
]{metricas/data.dat}
答案1
您可以执行自定义预处理
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread[]{
a b
some 52894
stuff 3600
dummy 7201
}\mytable
\pgfplotstabletypeset[1000 sep=,
columns/a/.style={string type},
columns/b/.style={string type,
preproc cell content/.code={%
\pgfkeysgetvalue{/pgfplots/table/@cell content}\myvar%
\pgfkeys{/pgf/fpu}%
\pgfmathparse{floor(\myvar/3600)}%
\pgfmathfloattoint{\pgfmathresult}%
\edef\hhh{\pgfmathresult}%
\pgfmathparse{floor((\myvar-\hhh*3600)/60)}%
\pgfmathfloattoint{\pgfmathresult}%
\edef\mmm{\pgfmathresult}%
\pgfmathparse{\myvar-\hhh*3600 - \mmm*60}%
\pgfmathfloattoint{\pgfmathresult}%
\edef\sss{\pgfmathresult}%
\edef\temp{%
\noexpand\pgfkeyssetvalue{/pgfplots/table/@cell content}{\hhh h\mmm m\sss s}}%
\temp%
\pgfkeys{pgf/fpu=false}%
},
}
]\mytable
\end{document}
虽然不是最有效的计算,但展示了基本的方法。