使用 csvsimple 包中的 \csvautolongtable 命令为表格创建标题

使用 csvsimple 包中的 \csvautolongtable 命令为表格创建标题

我使用 csvsimple 包中的 \csvautolongtable 命令成功包含了一个 .csv 表(该表不止一页,这就是我使用此命令的原因)。现在我想为该表添加标题和标签,但我不知道该怎么做。非常感谢任何帮助。提前致谢!

这是我的最小例子

\documentclass[pdftex,a4paper]{scrartcl}
\usepackage[german, english]{babel} 
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{longtable}

\begin{document}
  %?\caption{There should be a caption somehow}
  %?\label{and a label...}
    \csvautolongtable[respect all]{chemicaltable.csv}
\end{document}

我的 csv 文件如下所示:

Known effect,Group
microcystin; DNA damage,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
reactive,A
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
anticancer,C
anticancer,C
anticancer,C
antirheumaticum,C
calcium pathway,C
gsk inhibitor,C
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
sterol pathway,E
sterol pathway,E
antirheumaticum,F
cyclooxygenase,F
low tox; antiinflammatory,F
endogenous,F
Antibiotic,G
Antibiotic,G
serotonin,H
serotonin,H
flame retardant,I
unknown,I
low tox. food,J
low tox. food,J
low tox; antiinflammatory,K
non toxic in fish-embryo,K
unknown,K
unknown,K
antiepileptic,L
antiepileptic; low tox,L
antiepileptic,M
dopamine receptors and others,M
adenosin receptor,N
nephrotox; adenosin,N
opiod receptor,O
ache inhibitor,P
Thyroid,Q
glucocorticoid,R
retinol pathway,x
Hif1 alpha pathway,y
hedgehog pathway,z

答案1

您可以使用table headegreg 所做的操作并添加一些内容:

\csvautolongtable[
      table head=\caption{some table}\label{tab:some}\\\hline
               \csvlinetotablerow\\\hline
               \endfirsthead\hline
               \csvlinetotablerow\\\hline
               \endhead\hline
               \endfoot,
               respect all
               ]{chemicaltable.csv}

完整代码:

\documentclass[pdftex,a4paper]{scrartcl}
\usepackage[german, english]{babel}
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{caption}
\usepackage{longtable}
\usepackage{filecontents}
\begin{filecontents*}{chemicaltable.csv}
  Known effect,Group
microcystin; DNA damage,A
reactive,A
reactive,A
reactive,A
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
anticancer,C
anticancer,C
anticancer,C
antirheumaticum,C
calcium pathway,C
gsk inhibitor,C
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
sterol pathway,E
sterol pathway,E
antirheumaticum,F
cyclooxygenase,F
low tox; antiinflammatory,F
endogenous,F
Antibiotic,G
\end{filecontents*}

\setlength{\textheight}{7cm}


\begin{document}
  %?\caption{There should be a caption somehow}
  %?\label{and a label...}
    \csvautolongtable[
      table head=\caption{some table}\label{tab:some}\\\hline
               \csvlinetotablerow\\\hline
               \endfirsthead\hline
               \csvlinetotablerow\\\hline
               \endhead\hline
               \endfoot,
               respect all
               ]{chemicaltable.csv}

Here is my table~\ref{tab:some}
\end{document}

在此处输入图片描述

在此处输入图片描述

答案2

标题应该是表格的一部分,通常在“第一个标题”中;您可以在读入文件longtable内容之前插入材料:csvtable head

\begin{filecontents*}{chemicaltable.csv}
  Known effect,Group
microcystin; DNA damage,A
reactive,A
reactive,A
reactive,A
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
anticancer,C
anticancer,C
anticancer,C
antirheumaticum,C
calcium pathway,C
gsk inhibitor,C
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
sterol pathway,E
sterol pathway,E
antirheumaticum,F
cyclooxygenase,F
low tox; antiinflammatory,F
endogenous,F
Antibiotic,G
\end{filecontents*}

\documentclass[a4paper]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[german, english]{babel}

\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{caption}
\usepackage{longtable}

\begin{document}

\csvautolongtable[
  table head={
    \caption{some table}\label{tab:some} \\
    \hline
    \endfirsthead
    \hline
    \endfoot
  },
  respect all
]{chemicaltable.csv}

\end{document}

在此处输入图片描述

相关内容