T-F-S / csvsimple

A LaTeX package for lightweight CSV file processing.
http://www.ctan.org/pkg/csvsimple
LaTeX Project Public License v1.3c
24 stars 5 forks source link

[Q] Supress last empty line? #2

Closed egorpugin closed 6 years ago

egorpugin commented 6 years ago

Hi,

I'm using \csvloop like this and get the new line or whatever at the end for some reason. Thus my table is showed incorrectly. (Manual table fill works fine.)

Is this a bug or is there a way to supress it? I tried some simple changes in the style file but did not succeed.

Screenshot: Image of Yaktocat

Simple repro with yours example:

\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*}

\begin{document}

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

\end{document}

You'll get the last empty row.

T-F-S commented 6 years ago

This is not a bug. It is also not a feature, but just normal behaviour.

In a table, there should be no stuff between \\\hline and \end{tabular}. With the given code, there is some internal processing which results in the empty table line.

The line can be easily suppressed, if the late after line option is used which puts code after this internal processing. You will find this in the documentation everywhere for tables.

With the given example, you need the following modification:

\documentclass{article}
\usepackage{csvsimple}

\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*}

\begin{document}

    \begin{tabular}{l|c}%
    \csvreader[head to column names,
      late after line=\\\hline%  <------------------
    ]{grade.csv}{}% use head of csv as column names
    {\givenname\ \name & \matriculation}% specify your coloumns here
    \end{tabular}

\end{document}
egorpugin commented 6 years ago

Thank you!