我正在尝试从 .dat 文件打印表格。文件中有些列不是数字而是文字,我认为这就是出现此错误的原因。我该如何修复它?
\documentclass[a4paper,twoside,12pt]{book}
\usepackage[table]{xcolor}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage{selinput}
\usepackage{chemfig}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\usepackage{verbatim}
\usepackage{a4}
\usepackage{tkz-kiviat,numprint}
\usepackage{pgfplotstable, pgfplots, filecontents}
\usepackage{eurosym}
\usepackage{caption,setspace}
\usepackage{quoting}
\usepackage[version=3]{mhchem}
\usepackage{booktabs, array}
\usepackage{tabularx}
\usepackage{arrayjobx}
\usepackage{siunitx}
\usepackage{url}
\usepackage{mwe}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{float}
\usepackage{xstring}
\usepackage{threeparttable}
\usepackage{xifthen}
\raggedbottom
\usetikzlibrary{arrows}
\quotingsetup{font=small}
\captionsetup{font={small,stretch=1}}
\begin{document}
\begin{filecontents}{Work.dat}
Sample Fe Mn B Cu Mo Co Ni Zn Ca Mg Na K P S Al Ti Cr Cd Pb As Se
F-C-Pr 31 19 15 11 <1 <0.9 <1 14 5500 1590 400 9100 1190 590 22 0.66 0.46 <0.3 <3 <4 <7
F-Pa-Pr 26 16 17 36 <1 <0.9 <1 40 7600 1690 970 8000 940 620 20 0.84 <0.4 <0.3 <3 <4 <7
F-W-Pr 22 25 16 11 <1 <1 <1 53 7800 1640 310 5800 1480 620 9.8 0.42 <0.4 <0.3 <3 <4 <8
F-C-S 33 28 30 21 1.6 <1 <1 27 3400 3300 3300 23000 790 710 22 0.62 <0.4 <0.3 <3 <4 <8
F-M-S 69 6.8 50 12 <1 <0.9 3.2 25 5200 1480 3400 25000 1280 510 28 0.81 <0.4 <0.3 <3 <4 <7
F-Pa-S 20 21 29 19 <1 <1 <1 14 5400 1740 9600 19300 540 800 6.6 0.61 <0.4 <0.3 <3 <4 <8
F-W-S 25 23 35 12 <1 <0.9 <1 11 3800 1260 500 24000 1660 520 13 3.1 <0.4 <0.3 <3 <4 <7
4-Pa-Pr 89 47 43 74 1.2 <1 3.1 89 19800 4400 2600 18900 2800 480 50 1.8 5.3 <0.3 <3 <4 <8
5-Pa-Pr 98 38 36 77 <1 <0.9 6 121 18300 4300 2100 18300 3200 620 31 1.3 11 <0.3 <3 <4 <8
6-Pa-Pr 177 49 45 93 1 <0.9 14 123 21000 4900 2100 21000 3500 780 38 2.2 27 <0.2 <2 <4 <7
6-C-Pr 83 57 42 59 <1 <1 2.6 54 18700 5500 3100 26000 4200 670 51 1.9 2.8 <0.3 <3 <4 <8
6-M-Pr 196 121 48 43 1.5 <1 12 210 32000 5200 2400 13300 3900 1240 63 2.2 20 <0.3 5.6 <4 <8
6-W-Pr 108 91 52 38 <1 <1 4 172 26000 5600 2600 19800 4800 760 33 1.3 7 <0.3 <3 <4 <8
7-Pa-Pr 149 56 60 133 <0.9 <0.9 7 124 26000 6000 2900 26000 3700 1220 58 3.7 13 <0.2 4.5 <3 <7
4-Pa-S 79 46 58 50 <1 <0.9 1.7 34 12400 3000 14500 42000 1410 710 31 1.4 2.4 <0.2 <2 <4 <7
5-Pa-S 96 57 69 65 <1 <1 2.5 47 14700 3800 17200 48000 1670 980 50 2.5 4.1 <0.3 <3 <4 <8
6-Pa-S 81 54 72 59 <1 <0.9 7.4 42 15100 3800 18200 51000 1670 1060 38 3.4 1.4 <0.3 <3 <4 <7
6-C-S 168 79 77 67 1.4 <1 4 79 11000 8500 7500 59000 2400 1270 122 4.2 5.2 <0.3 <3 <4 <8
6-M-S 190 17 124 34 <1 <0.9 9.2 53 13000 3600 7600 60000 3100 810 89 6.7 5.2 <0.3 <3 <4 <8
6-W-S 200 73 98 59 <1 <0.9 6 49 9000 3800 3800 75000 4200 1020 45 1.9 15 <0.3 <3 <4 <8
7-Pa-S 141 68 81 65 <1 <1 2.9 46 16600 4600 19500 58000 1880 1330 45 3.9 4 <0.3 <3 <4 <8
\end{filecontents}
\pgfplotstabletypeset[
col sep = space,
string replace*={_}{\textsubscript},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column name={}}
display columns/5/.style={string type}
display columns/6/.style={string type}
display columns/7/.style={string type}
display columns/18/.style={string type}
display columns/19/.style={string type}
display columns/20/.style={string type}
display columns/21/.style={string type}
]
{Workbook1.dat}
\end{document}
答案1
你在 , 之间缺少一些逗号,在倒数第五列也display columns
缺少一些逗号。但是表格太大了,无法放在一页中。我稍微缩小了字体大小,现在它可以放在横向页面中了。<
\tabcolsep
我还将列更改为<
数学模式,这需要一个解决方法(灵感来自如何旋转 pgfplotstable 的头行单元格条目)获取标题单元格不是在数学模式中。
如果表格显得太拥挤,您可以减小字体大小并增加\tabcolsep
。
\documentclass[a4paper,twoside,12pt]{book}
\usepackage{pgfplotstable,pgfplots,booktabs,filecontents,pdflscape}
\newcolumntype{M}{>{$}c<{$}}
\usepackage[T1]{fontenc}
\begin{document}
\begin{filecontents}{Work.dat}
Sample Fe Mn B Cu Mo Co Ni Zn Ca Mg Na K P S Al Ti Cr Cd Pb As Se
F-C-Pr 31 19 15 11 <1 <0.9 <1 14 5500 1590 400 9100 1190 590 22 0.66 0.46 <0.3 <3 <4 <7
F-Pa-Pr 26 16 17 36 <1 <0.9 <1 40 7600 1690 970 8000 940 620 20 0.84 <0.4 <0.3 <3 <4 <7
F-W-Pr 22 25 16 11 <1 <1 <1 53 7800 1640 310 5800 1480 620 9.8 0.42 <0.4 <0.3 <3 <4 <8
F-C-S 33 28 30 21 1.6 <1 <1 27 3400 3300 3300 23000 790 710 22 0.62 <0.4 <0.3 <3 <4 <8
F-M-S 69 6.8 50 12 <1 <0.9 3.2 25 5200 1480 3400 25000 1280 510 28 0.81 <0.4 <0.3 <3 <4 <7
F-Pa-S 20 21 29 19 <1 <1 <1 14 5400 1740 9600 19300 540 800 6.6 0.61 <0.4 <0.3 <3 <4 <8
F-W-S 25 23 35 12 <1 <0.9 <1 11 3800 1260 500 24000 1660 520 13 3.1 <0.4 <0.3 <3 <4 <7
4-Pa-Pr 89 47 43 74 1.2 <1 3.1 89 19800 4400 2600 18900 2800 480 50 1.8 5.3 <0.3 <3 <4 <8
5-Pa-Pr 98 38 36 77 <1 <0.9 6 121 18300 4300 2100 18300 3200 620 31 1.3 11 <0.3 <3 <4 <8
6-Pa-Pr 177 49 45 93 1 <0.9 14 123 21000 4900 2100 21000 3500 780 38 2.2 27 <0.2 <2 <4 <7
6-C-Pr 83 57 42 59 <1 <1 2.6 54 18700 5500 3100 26000 4200 670 51 1.9 2.8 <0.3 <3 <4 <8
6-M-Pr 196 121 48 43 1.5 <1 12 210 32000 5200 2400 13300 3900 1240 63 2.2 20 <0.3 5.6 <4 <8
6-W-Pr 108 91 52 38 <1 <1 4 172 26000 5600 2600 19800 4800 760 33 1.3 7 <0.3 <3 <4 <8
7-Pa-Pr 149 56 60 133 <0.9 <0.9 7 124 26000 6000 2900 26000 3700 1220 58 3.7 13 <0.2 4.5 <3 <7
4-Pa-S 79 46 58 50 <1 <0.9 1.7 34 12400 3000 14500 42000 1410 710 31 1.4 2.4 <0.2 <2 <4 <7
5-Pa-S 96 57 69 65 <1 <1 2.5 47 14700 3800 17200 48000 1670 980 50 2.5 4.1 <0.3 <3 <4 <8
6-Pa-S 81 54 72 59 <1 <0.9 7.4 42 15100 3800 18200 51000 1670 1060 38 3.4 1.4 <0.3 <3 <4 <7
6-C-S 168 79 77 67 1.4 <1 4 79 11000 8500 7500 59000 2400 1270 122 4.2 5.2 <0.3 <3 <4 <8
6-M-S 190 17 124 34 <1 <0.9 9.2 53 13000 3600 7600 60000 3100 810 89 6.7 5.2 <0.3 <3 <4 <8
6-W-S 200 73 98 59 <1 <0.9 6 49 9000 3800 3800 75000 4200 1020 45 1.9 15 <0.3 <3 <4 <8
7-Pa-S 141 68 81 65 <1 <1 2.9 46 16600 4600 19500 58000 1880 1330 45 3.9 4 <0.3 <3 <4 <8
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = space,
every head row/.style={%
before row=\toprule,
after row=\midrule,
typeset cell/.code={
\ifnum\pgfplotstablecol=\pgfplotstablecols
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\multicolumn{1}{c}{##1}\\}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\multicolumn{1}{c}{##1}&}%
\fi
}
},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column type={l}},
display columns/5/.style={string type,column type={M}},
display columns/6/.style={string type,column type={M}},
display columns/7/.style={string type,column type={M}},
display columns/17/.style={string type,column type={M}},
display columns/18/.style={string type,column type={M}},
display columns/19/.style={string type,column type={M}},
display columns/20/.style={string type,column type={M}},
display columns/21/.style={string type,column type={M}}]
{Work.dat}
\end{landscape}
\end{document}