0

I started learning LaTeX (on Overleaf) and I have to insert a table. Due to the size of the table, for convenience I want to import it as CSV.

I replicated the same code from internet (as Importing csv file into latex as a table )

With this code

\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' witha4paper' 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}

I got this error

Extra }, or forgotten \endgroup. Missing \endcsname inserted.

This is the csv, located in csv_dir folder

\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*}
Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • 3
    Please provide a fully compileable document, from \documentclass{... to \end{document}. Also provide the content of the external csv file that you are loading. As it stands it is impossible to diagnose your issue. – Willie Wong Jul 25 '23 at 02:30
  • Well, the only difference to the answer you linked (which works for me) is "Figures/", so is your csv in the Figures folder? And did you include the package csvsimple (you didn't provide a MWE, as maybe the header of your csv is different?)? – canIchangethis Jul 25 '23 at 07:22

1 Answers1

2

Does your csv file actually start with \begin{filecontents*}...?

If so, please delete the first line (\begin{filecontents*}{grade.csv}) and the last line (\end{filecontents*}). They do not belong in the actual csv file.


The filecontents environment is a way to embed external data into the actual TeX file. When included in a tex file, when run, a modern TeX engine will extract the contents of the filecontents environment and dump it into a file with the specified name. This makes it easier for users to copy-and-paste when discussing code on an internet forum (such as this one): instead of pasting into two separate files that the user has to create by hand with the appropriate file name, using filecontents allows pasting only once into a file with essentially arbitrary name. See this for more info on how to use it.

It is not meant to be part of the csv file in the example you linked to.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106