我是 LaTeX 的新手,目前面临在文档中插入长表格的问题。
我有一张长表格.csv
,我希望将其插入到具有多列和一个表格标题的文档中,如上图所示。
这是我的代码:
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{booktabs}
\usepackage{filecontents}
\begin{filecontents}{pgfplotstable.data.csv}
Station,Lat,Lon,dg
1,-3.36867,36.625,-3.073
2,-2.41667,34.82917,12.68
3,-2.65833,31.3805,17.198
4,-1.32083,31.8195,-15.783
5,-6.825,39.28883,0.23
6,-6.835,39.26667,4.181
7,-6.82167,39.29633,0.722
8,-6.87633,39.20417,10.3
9,-6.87633,39.20333,3.298
10,-6.81917,39.28583,-0.891
11,-6.82167,39.29633,0.832
12,-6.855,39.28,4.102
13,-6.8,39.28333,-0.802
14,-6.82083,39.2875,-0.976
15,-6.16667,35.74583,-7.897
16,-2.87217,32.16383,-1.286
17,-7.875,32.48333,-36.034
18,-7.66117,35.76383,33.337
19,-4.56667,30.1,6.455
20,-1.77217,30.84333,-7.361
21,-4.87833,29.66667,-30.593
22,-8.775,39.40833,11.588
23,-8.912,39.51167,2.149
24,-4.89583,35.76833,1.135
25,-6.16667,36.42417,-7.367
26,-2.0625,35.54167,52.271
27,-10.74,38.76617,-15.588
28,-8.89167,33.44167,35.769
29,-8.91383,33.4555,35.369
30,-6.82117,37.65133,-15.818
31,-3.355,37.33,-38.447
32,-6.35433,31.07715,-14.84
33,-10.25,40.1,29.713
34,-2.42883,32.93133,-19.348
35,-9.3545,34.77083,103.94
36,-6.71667,32.06883,14.056
37,-3.40967,35.6125,-8.271
38,-8.34433,35.3055,61.539
39,-4.26667,34.18333,-31.827
40,-3.61667,33.5005,-42.218
41,-4.80967,34.7235,11.81
42,-10.67917,35.57367,21.493
43,-10.67917,35.5735,21.553
44,-7.94633,31.60883,98.383
45,-7.94633,31.60883,98.373
46,-5.07217,32.83617,-33.351
47,-5.08333,32.83333,-38.775
48,-5.07217,32.83617,-33.351
49,-5.0875,39.0695,-28.979
50,-5.1,39.06667,-24.826
51,-5.0875,39.0695,-28.949
52,-11.10133,37.36917,-23.768
53,-11.10133,37.36917,-23.688
54,-5.08933,30.40533,-18.289
55,-6.21667,39.21667,12.413
56,-6.21667,39.21667,12.443
\end{filecontents}
\begin{document}
\pgfplotstableset{
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}}
%
\pgfplotstabletypeset[
columns={Station,Lat,Lon,dg,Station,Lat,Lon,dg,Station,Lat,Lon,dg},
display columns/0/.style={select equal part entry of={0}{3},string type},% first part of ‘station’
display columns/1/.style={select equal part entry of={0}{3},string type},% first part of ‘lat’
display columns/2/.style={select equal part entry of={0}{3},string type},% first part of ‘lon’
display columns/3/.style={select equal part entry of={0}{3},string type},% first part of ‘dg’
display columns/0/.style={select equal part entry of={1}{3},string type},% Second part of ‘station’
display columns/1/.style={select equal part entry of={1}{3},string type},% Second part of ‘lat’
display columns/2/.style={select equal part entry of={1}{3},string type},% Second part of ‘lon’
display columns/3/.style={select equal part entry of={1}{3},string type},% Second part of ‘dg’
display columns/0/.style={select equal part entry of={2}{3},string type},% Third part of ‘station’
display columns/1/.style={select equal part entry of={2}{3},string type},% Third part of ‘lat’
display columns/2/.style={select equal part entry of={2}{3},string type},% Third part of ‘lon’
display columns/3/.style={select equal part entry of={2}{3},string type},% Third part of ‘dg'
]{pgfplotstable.data.csv}
\end{document}
当我编译代码时收到一条错误消息:
包 pgfplots 错误:抱歉,无法从表 'pgfplotstable.data.csv' 中检索列 'Station'。请检查拼写(或引入名称别名)。
我哪里搞砸了?
答案1
由于您没有指定列分隔符为comma
,因此 pgfplots 默认为space
字符。因此,它无法读取您的表格。
只需指定它是逗号:col sep=comma,
我引用pgfplotstable
手册第 5 页的内容:
/pgfplots/table/col sep=space|tab|comma|semicolon|colon|braces|&|ampersand (initially space)
指定用于表格读取的列分隔符。初始选择为空格,表示“至少一个空格”。空格是制表位或空格(换行符始终用于分隔行)。
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{booktabs}
\usepackage{filecontents}
\begin{filecontents}{pgfplotstable.data.csv}
Station,Lat,Lon,dg
1,-3.36867,36.625,-3.073
2,-2.41667,34.82917,12.68
3,-2.65833,31.3805,17.198
4,-1.32083,31.8195,-15.783
5,-6.825,39.28883,0.23
6,-6.835,39.26667,4.181
7,-6.82167,39.29633,0.722
8,-6.87633,39.20417,10.3
9,-6.87633,39.20333,3.298
10,-6.81917,39.28583,-0.891
11,-6.82167,39.29633,0.832
12,-6.855,39.28,4.102
13,-6.8,39.28333,-0.802
14,-6.82083,39.2875,-0.976
15,-6.16667,35.74583,-7.897
16,-2.87217,32.16383,-1.286
17,-7.875,32.48333,-36.034
18,-7.66117,35.76383,33.337
19,-4.56667,30.1,6.455
20,-1.77217,30.84333,-7.361
21,-4.87833,29.66667,-30.593
22,-8.775,39.40833,11.588
23,-8.912,39.51167,2.149
24,-4.89583,35.76833,1.135
25,-6.16667,36.42417,-7.367
26,-2.0625,35.54167,52.271
27,-10.74,38.76617,-15.588
28,-8.89167,33.44167,35.769
29,-8.91383,33.4555,35.369
30,-6.82117,37.65133,-15.818
31,-3.355,37.33,-38.447
32,-6.35433,31.07715,-14.84
33,-10.25,40.1,29.713
34,-2.42883,32.93133,-19.348
35,-9.3545,34.77083,103.94
36,-6.71667,32.06883,14.056
37,-3.40967,35.6125,-8.271
38,-8.34433,35.3055,61.539
39,-4.26667,34.18333,-31.827
40,-3.61667,33.5005,-42.218
41,-4.80967,34.7235,11.81
42,-10.67917,35.57367,21.493
43,-10.67917,35.5735,21.553
44,-7.94633,31.60883,98.383
45,-7.94633,31.60883,98.373
46,-5.07217,32.83617,-33.351
47,-5.08333,32.83333,-38.775
48,-5.07217,32.83617,-33.351
49,-5.0875,39.0695,-28.979
50,-5.1,39.06667,-24.826
51,-5.0875,39.0695,-28.949
52,-11.10133,37.36917,-23.768
53,-11.10133,37.36917,-23.688
54,-5.08933,30.40533,-18.289
55,-6.21667,39.21667,12.413
56,-6.21667,39.21667,12.443
\end{filecontents}
\begin{document}
\pgfplotstableset{
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}}
%
\pgfplotstabletypeset[col sep=comma,% <-- specifies that the comma is the column separator
columns={Station,Lat,Lon,dg,Station,Lat,Lon,dg,Station,Lat,Lon,dg},
display columns/0/.style={select equal part entry of={0}{3},string type},% first part of ‘station’
display columns/1/.style={select equal part entry of={0}{3},string type},% first part of ‘lat’
display columns/2/.style={select equal part entry of={0}{3},string type},% first part of ‘lon’
display columns/3/.style={select equal part entry of={0}{3},string type},% first part of ‘dg’
display columns/0/.style={select equal part entry of={1}{3},string type},% Second part of ‘station’
display columns/1/.style={select equal part entry of={1}{3},string type},% Second part of ‘lat’
display columns/2/.style={select equal part entry of={1}{3},string type},% Second part of ‘lon’
display columns/3/.style={select equal part entry of={1}{3},string type},% Second part of ‘dg’
display columns/0/.style={select equal part entry of={2}{3},string type},% Third part of ‘station’
display columns/1/.style={select equal part entry of={2}{3},string type},% Third part of ‘lat’
display columns/2/.style={select equal part entry of={2}{3},string type},% Third part of ‘lon’
display columns/3/.style={select equal part entry of={2}{3},string type},% Third part of ‘dg'
]{pgfplotstable.data.csv}
\end{document}