0

Before someone marks this as a duplicate question, I have read this answer, and it has not helped.

I have a csv file:

"headline","similarity"
"Tesco directors in scandal",""
"Tesco suspends three more senior staff over profits scandal","0.7443551421165466"
"\textsterling11m bonus for Tesco boardroom","0.7385022044181824"
"SSL inquiry claims two boardroom casualties","0.7339619398117065"
"Morrisons executive arrested in insider trading investigation","0.7273239493370056"
"Tesco rubbishes 'chief executive to quit' report","0.7250239849090576"

And I'm trying to read it in using:

\begin{table}
    \small
    \renewcommand{\arraystretch}{1.2}
    \sisetup{group-digits=false, table-format=1.3, table-auto-round=true, table-number-alignment = left}
    \begin{tabularx}{\columnwidth}{@{}XS@{}} \toprule
        {Headline} & {Similarity} \\\midrule
        \csvreader[
        late after line=\\,
        late after last line=\\\midrule,
        head to column names,
        before reading={\catcode`\"=9}]
        {../file.csv}
        {}
        {\csviffirstrow{\textbf}{} \headline & \similarity}
    \end{tabularx}
\end{table}

But this gives:

enter image description here

How can I remove the quotes here?

I believe I need them in the first place because, if they are not there, the \textsterling in the 4th line of the csv does not parse correctly.

3

The issue with the quotes can be solved by setting the catcode in wider scope, for example within the table environment. This may appear not to work because of a second issue, which is that commands (such as \textsterling) are not allowed at the start of a line (probably related to Strange csvsimple output when the line starts with an accented character). When you put something else at the start, for example an empty group {}, then it works as expected.

Note that the catcode character does not need a backslash (i.e., \catcode`"=9 works). As a small detail you can also consider to use `chief executive to quit' (starting with a backtick instead of a normal quote) to get directional quotes in the output.

MWE:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{siunitx}

\begin{document}
\begin{table}
    \catcode`"=9
    \small
    \renewcommand{\arraystretch}{1.2}
    \sisetup{group-digits=false, table-format=1.3, table-auto-round=true, table-number-alignment = left}
    \begin{tabularx}{\columnwidth}{@{}XS@{}} \toprule
        {Headline} & {Similarity} \\\midrule
        \csvreader[
        late after line=\\,
        late after last line=\\\midrule,
        head to column names,
        %before reading={\catcode`\"=9},
        ]
        {tesco.csv}
        {}
        {\csviffirstrow{\textbf}{} \headline & \similarity}
    \end{tabularx}
\end{table}
\end{document}

CSV:

"headline","similarity"
"Tesco directors in scandal",""
"Tesco suspends three more senior staff over profits scandal","0.7443551421165466"
"{}\textsterling11m bonus for Tesco boardroom","0.7385022044181824"
"SSL inquiry claims two boardroom casualties","0.7339619398117065"
"Morrisons executive arrested in insider trading investigation","0.7273239493370056"
"Tesco rubbishes `chief executive to quit' report","0.7250239849090576"

Result:

enter image description here

  • Thanks a lot Marijn - really appreciate your help! – Henry Apr 1 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.