# Importing csv Table with Underscores

I have to import a csv table whose entries contain underscores. A simple example is the following table:

FirstCol, SecondCol
Item_A, Item_B


I am trying to solve my problem with the csvsimple package with the "respect underscore=true" option. Here is a minimal working example:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{longtable}
\usepackage{csvsimple}
\usepackage{array,booktabs}
\usepackage[T1]{fontenc}

\begin{document}

\begin{longtable}{|l|l|}
\hline
late after line=\\\hline]{Test.csv}{}{\FirstCol & \SecondCol}
\end{longtable}

\end{document}


This code produces the following result:

How do I get rid of the obviously wrong column separators just below the table? To be clear, what I would like is this:

Note that the two separators only appear if the "respect underscore=true" option is present. If I remove this option (and delete the underscores from the input file), then all works as expected.

• This is not a duplicate of this question. The latter question was concerned with the underscore not being rendered properly; the present question is concerned with the unwanted column separators appended just under the table. Jan 23, 2018 at 0:32
• Apparently it doesn't like being inside a table. Try \csvreader[longtable={|l|l|},table head=\hline,respect underscore=true,head to column names,late after line=\\\hline]{test.csv}{}{\FirstCol & \SecondCol} instead. Jan 23, 2018 at 1:04

A solution could be pgfplotstable with the verb string type option.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{longtable}
\usepackage{array,booktabs}
\renewcommand*{\arraystretch}{1.2}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}

\usepackage{filecontents}
\begin{filecontents}{Test.csv}
FirstCol, SecondCol
Item_A, Item_B
\end{filecontents}

\begin{document}

\pgfplotstabletypeset[
begin table={\begin{longtable}},
\hline
\hline
FirstCol & SecondCol\\
\hline

• If at all possible, I would prefer to stay with the csvsimple package. We are using it in all our documents and we have developed macros and commands around it. Also, I do not see why it should not be possible to make it work (unless there is a bug in the package, of course). Jan 23, 2018 at 20:17