
我正在嘗試使用 pgfplotstable 將資料載入到某些表中。我的問題是,文件中的資料的格式與我想要在表中呈現的方式有點不同,並且在轉換它之後,「丟失」了一些行資料。在網路上搜尋後,我無法想出可行的方法,所以我來了!
我不太擅長描述它,所以我只給你看一個例子。我要這個:
但到目前為止我只能這樣做:
我用來創建這個簡短演示的程式碼如下(所有“pgfplotstableread”都將通過使用“pgfplotstabletranspose”從文件加載相同的資料來替換):
\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\begin{document}
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}
\pgfplotstableset{%
every head row/.style={
before row={%
\toprule
\ensuremath{r_{lesion}} & \multicolumn{4}{c}{\ensuremath{E_{nom}}} \\
},
after row=\midrule
},
every last row/.style={after row=\bottomrule}
}
\pgfplotstabletypeset[
numeric type,
columns/(mm)/.style={
column type=r
}
]{
(mm) 0.32 0.56 1.80 3.20
5 0.98 1.03 1.26 1.47
10 0.84 0.95 1.44 1.74
15 0.05 0.65 1.86 2.57
20 0.03 0.52 2.13 3.19
}
\vspace{0.5in}
\pgfplotstableread{
sr esr
0.32 0.98
0.56 1.03
1.8 1.26
3.2 1.47
}\rowA
\pgfplotstableread{
sr esr
0.32 0.84
0.56 0.95
1.8 1.44
3.2 1.74
}\rowB
\pgfplotstableread{
sr esr
0.32 0.05
0.56 0.65
1.8 1.86
3.2 2.57
}\rowC
\pgfplotstableread{
sr esr
0.32 0.03
0.56 0.52
1.8 2.13
3.2 3.19
}\rowD
\pgfplotstabletranspose[columns=esr, numeric type]{\transA}{\rowA}
\pgfplotstabletranspose[columns=esr, numeric type]{\transB}{\rowB}
\pgfplotstabletranspose[columns=esr, numeric type]{\transC}{\rowC}
\pgfplotstabletranspose[columns=esr, numeric type]{\transD}{\rowD}
\pgfplotstablevertcat{\renderedTable}{\transA}
\pgfplotstablevertcat{\renderedTable}{\transB}
\pgfplotstablevertcat{\renderedTable}{\transC}
\pgfplotstablevertcat{\renderedTable}{\transD}
\pgfplotstabletypeset[
columns/colnames/.style={
numeric type,
column name={(mm)},
column type=r
},
columns/0/.style={
column name={0.32}
},
columns/1/.style={
column name={0.56}
},
columns/2/.style={
column name={1.80}
},
columns/3/.style={
column name={3.20}
}
]\renderedTable
\end{document}
如果我將“colnames”更改回字串類型,它會顯示“esr”而不是“NaN”,但我仍然希望能夠在文件中手動輸入這些值,以便我可以執行以下操作:
\defineColumnOneRows{5,10,20,25}
並將這些值放入第一列的行中。
非常感謝您提供的任何幫助!謝謝參觀!