readcsv不工作

readcsv不工作

我开始学习 LaTeX(在 Overleaf 上),我需要插入一个表格。由于表格的大小,为了方便起见,我想将其导入为 CSV。

我从互联网上复制了相同的代码(将 csv 文件作为表格导入到 latex 中

使用此代码

\documentclass{book}

% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}

% Set page size and margins
% Replace `letterpaper' with `a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{csvsimple}

\title{Your Paper}
\author{You}

\begin{document}
\maketitle


\section{Introduction}

\begin{tabular}{l|c}%
    \bfseries Person & \bfseries Matr.~No.% specify table head
    \csvreader[head to column names]{csv_dir/grade.csv}{}% use head of csv as column names
    {\\\hline\givenname\ \name & \matriculation}% specify your coloumns here
\end{tabular}

\section{Some examples to get started}



\bibliographystyle{alpha}
\bibliography{sample}

\end{document}

我收到这个错误

额外的 },或忘记了 \endgroup。缺少插入的 \endcsname。

这是 csv,位于csv_目录文件夹

\begin{filecontents*}{grade.csv}
name,givenname,matriculation,gender,grade
Maier,Hans,12345,m,1.0
Huber,Anna,23456,f,2.3
Weisbaeck,Werner,34567,m,5.0
\end{filecontents*}

答案1

您的csv文件实际上是以 开头的吗\begin{filecontents*}...

如果是的话,请删除第一行 ( \begin{filecontents*}{grade.csv}) 和最后一行 ( \end{filecontents*})。它们不要属于实际csv文件。


环境filecontents是一种将外部数据嵌入实际 TeX 文件的方法。当包含在文件中时tex,运行时,现代 TeX 引擎将提取filecontents环境的内容并将其转储到具有指定名称的文件中。这使得用户在互联网论坛(例如这个)上讨论代码时更容易复制和粘贴:而不是粘贴到用户必须手动创建具有适当文件名的两个单独文件中,使用filecontents允许仅粘贴一次到具有任意名称的文件中。请参阅此处以获取有关如何使用它的更多信息。

它并不是csv您所链接的示例中文件的一部分。

相关内容