TeX - LaTeX Asked by HaroldUlotu on July 28, 2020
I am new to LaTeX and I am currently facing a problem of inserting long tables to a document.
I have a long table .csv
and I wish to insert it in the document with multiple columns and a single table Header and caption like the image above.
Here’s my code:
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}
When I compile the code I get an error message:
Package pgfplots Error: Sorry, could not retrieve column ‘Station’ from table
‘pgfplotstable.data.csv’. Please check spelling (or introduce name aliases)..
Where am I messing up?
Since you didn't specify that the column separator is the comma, pgfplots defaults to the space character. Therefore, it can't read your table.
Just specify that it is the comma : col sep=comma,
I'm quoting from the page 5 of pgfplotstable
manual:
/pgfplots/table/col sep=spacejtabjcommajsemicolonjcolonjbracesj&jampersand (initially space)
Specifies the column separation character for table reading. The initial choice, space, means “at least one white space”. White spaces are tab stops or spaces (newlines characters always delimit lines). Therefore, it can't read your table. Just specify that it is the comma :
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}
Answered by AndréC on July 28, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP