(LaTeX 中的数据工具)DTLforeach:无法分配 XXX,XXX 中没有键?

(datatool in LaTeX)DTLforeach: Can't assign XXX there is no keys in XXX?

我是 LaTeX 的初学者,目前正在尝试从文本文件创建表格(出于某种原因数据是从其他程序生成并写入 .txt 文件)

这是其中一个文本文件:(刚刚将其集成到乳胶中)

\begin{filecontents*}{d11.csv}
Zeit/s AMES\_13 AMES\_14 AMES\_15 AMES\_16
3,0 000  8,760V 0,000  0,216mA
6,0 000  13,120V 0,000  0,169mA
9,0 000  16,550V 0,000  0,132mA
12,0 000  19,660V 0,000  0,103mA
15,0 000  21,730V 0,000  0,081mA
18,0 000  23,580V 0,000  0,066mA
\end{filecontents*}

并且我尝试使用包的 DTLforeach 生成乳胶 Table 形成它使用:

\DTLsetseparator{ }
\DTLloaddb[
           keys={zeit,am1,am2,am3,am4}
]{d11db}{d11.csv}

 .... Some other texts...

\begin{tabular}{|c|c|c|c|c|}
\bfseries Zeit/s &
\bfseries AMES\_13 &
\bfseries AMES\_14 &
\bfseries AMES\_15 &
\bfseries AMES\_16 \\hline
\DTLforeach{d11db}{\zeit=zeit,\am1=am1,\am2=am2,\am3=am3,\am4=am4
}{%
  \zeit & \am1 & \am2 & \am3 & \am4 \\hline
}
\end{tabular}

然后当我尝试编译它时,LaTeX(或 pdflatex)只是向我显示错误:

Package datatool Error: Can't assign \am4 : there is no key `am4 ' in data base `d11db'.

如果我删除 \am4=am4,它会显示 am3 不存在...有人能告诉我如何解决这个错误吗?谢谢(对不起我的英语不好)

keys 选项指定您在 CSV 中使用的实际 header 名称。这是 datatool user's guide(第 5.2 从外部 ASCII 文件 加载数据库)的节选:

keys

This is a comma-separated list of keys to use, where the keys are listed in the same order as the columns. If the file has a header, these keys will override the values given in the header row. If the file has no header row and no keys are supplied in <options>, then the keys will be given by \dtldefaultkey<n>, where <n> is the \dtldefaultkey column number and \dtldefaultkey defaults to “Column”. Note that the list of keys must be delimited by braces since they contain commas.

所以,我的建议是使用:

\begin{filecontents*}{d11.csv}
zeit,am1,am2,am3,am4
3,0 000  8,760V 0,000  0,216mA
...
\end{filecontents*}

\DTLloaddb[
  keys={zeit,am1,am2,am3,am4},
  headers={Zeit/s,AMES\_13,AMES\_14,AMES\_15,AMES\_16}
]{d11db}{d11.csv}

注意 headers 键的用法:

headers

This is a comma-separated list of headers. If not supplied, the header will be the same as that given in the header row, or the key if there is no header row. Note that the list of headers must be delimited by braces since they contain commas.