我有一个 csv 文件keywords_table.csv
。我在 Excel 中创建了它。它如下:
Keyword Category,Number of keywords used in searches,Examples
Names of drugs,111,"tamoxifen, aspirin, tamiflu"
Names of categories,15,"cancer drug, NSAID, flu vaccine"
"Synonyms for ""child"" and ""pediatric""",11,"pediatric, child, prepubertal, adolescent, teenage, early life, kid"
Names of physiological systems,47,"urinary, hematologic, cardiovascular, musculoskeletal, endocrine, sensory, reproductive, skin, salivary"
Names and synonyms of adverse drug reactions,10,"adverse event, adverse reaction, side effect, adverse drug reaction, AE, ADR, ADE"
Exclusion terms,5,"mouse, mice, rat, animal model, scale, addict"
我的目标:在我的 LaTeX 文档中放入一个表格。我想用一个单独的 csv 文件来实现这一点,因为这样我在其他软件中更新起来更方便,而不必在标准 Latex 表格中手动更改值。
我已经尝试了几个小时来使用csvsimple
它,但还没有成功。我阅读了该软件包的文档和在线的各种示例,试图让这个东西工作,但没有成功。我是一个 LaTeX 新手,所以如果这是一个微不足道的问题,我深表歉意。
我的 LaTeX 工作流程是 Windows 10 Pro 上的 MikTex,我使用的是 TexMaker。我使用 XeLaTeX 和 BibTex 进行渲染。这是我用来尝试使用表格的代码csvautotabular
,包括我的序言:
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{csquotes}
\MakeOuterQuote{"}
\usepackage{csvsimple}
\usepackage{longtable}
%\usepackage{tikz}
%\usepackage{pgf}
\usepackage{graphicx}
%\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{fullpage}
\usepackage{setspace}
\usepackage{fontspec}
\setmainfont{Adobe Garamond Pro}
\usepackage{color,soul}
\usepackage[left]{lineno}
\linenumbers
\doublespacing
\usepackage{anysize}
\usepackage[
backend=biber,
style=apa
]{biblatex}
\addbibresource{C:/stuff/bib.bib}
\title{HEY LOOK A TITLE}
\author{ME}
\begin{document}
\maketitle
\csvautotabular{keywords_table.csv}
\printbibliography
\end{document}
如果我删除 ,代码将完美执行\csvautotabular{keywords_table.csv}
。这就是我所做的一切。我不关心格式或其他任何事情。
以下是当我尝试运行 XeLaTeX 时 TexMaker 向我返回的一连串错误消息的屏幕截图:
这些对我来说是无法解释的。它在哪里插入了什么东西?我检查了整个文档,看是否缺少 { 或 },但无济于事。就像我说的,文档运行时没有这行\csvautotabular
。
再次抱歉。如能得到任何帮助我将非常感激。
答案1
我会等待,看看是否有更好的答案,因为我对这种类型的导入经验很少
但是,这是我的新手尝试。我不得不修改您的 csv 以适应加载方法,因此修改后的副本以简化 \headings 和“{include, commas}”嵌入到以下内容中,一旦运行,将文件内容保存到外部文件 testing.csv 中,删除该部分并查看其加载方式。在您自己的解决方案中,csv 可以是任何外部名称。
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%\usepackage{csquotes} % had problems trying to get complex file to use this package
%\MakeOuterQuote{''} % had problems trying to get complex file to use this package
\usepackage{csvsimple} %csvsimple is not able to cope reliably with " delimited comma entries
\usepackage{longtable}
%\usepackage{tikz}
%\usepackage{pgf}
\usepackage{graphicx}
%\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{fullpage}
\usepackage{setspace}
\usepackage{fontspec}
%\setmainfont{Adobe Garamond Pro} % I usually have problems with this family
\usepackage{color,soul}
\usepackage[left]{lineno}
\linenumbers
\doublespacing
\usepackage{anysize}
\usepackage[
backend=biber,
style=apa
]{biblatex}
%\addbibresource{C:/stuff/bib.bib} % don't have this stuff
% filecontents for demo can be external as per comment below
\begin{filecontents*}{testing.csv}
Category,Number,Examples
Names of drugs,111,"{tamoxifen, aspirin, tamiflu}"
Names of categories,15,"{cancer drug, NSAID, flu vaccine}"
"Synonyms for child and pediatric",11,"{pediatric, child, prepubertal, adolescent, teenage, early life, kid}"
Names of physiological systems,47,"{urinary, hematologic, cardiovascular, musculoskeletal, \cr && endocrine, sensory, reproductive, skin, salivary}"
Names and synonyms of adverse drug reactions,10,"{ADE, adverse drug event, ADR, adverse drug reaction, \cr && AE, adverse event, AR, adverse reaction, SE, side effect}"
Exclusion terms,5,"{mouse, mice, rat, animal model, scale, addict}"
\end{filecontents*}
\title{HEY LOOK A TITLE}
\author{ME}
\begin{document}
\maketitle
%\csvautotabular{keywords_table.csv} replaced with modifications per answer by egreg
%see https://tex.stackexchange.com/questions/424207/unable-to-print-without-quotes-in-csvsimple
\tiny \csvreader[
tabular=|l|c|l|,
table head=\hline Keyword Category & Searches & Examples of each\\\hline,
late after line=\\\hline,
head to column names,
before reading={\catcode`\"=9}
]{testing.csv}{} % you can replace "testing" with "keywords_table" filename
{%
\Category & \Number & \Examples
}%
\printbibliography
\end{document}