1

I am trying to show a table with two rows and 13 columns, through CSV and csvreader.

As you can see on the contents, there are two X's in the last column of the two rows. However, they are not shown in the column 'M' (see figure). What am I doing wrong?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple,longtable,booktabs}

\begin{filecontents*}{table7.csv}
A,B,C,D,E,F,G,H,I,J,K,L,M
Germany,GDP,X,X,,,,,,,X,,X
France,GDP,X,X,,X,,X,,,X,,X
\end{filecontents*}

\begin{document}

\csvreader[
  respect all,%
  longtable={|p{2cm}|p{2cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|},
  separator=comma,
  table head=\caption{List with data.\label{tab:mytable7}}\\
    \toprule\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \midrule\endfirsthead
    \bottomrule\endfoot,
  late after line=\\,
]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,12=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}

\end{document}

Column M does not show anything. However, the last column of the CSV file does store information

  • You wrote 12=\fieldl instead of 13=\fieldl. However your code could be improved. Do you really need a longtable for your actual data? Do you know that booktabs and vertical rules don't work well together? – CarLaTeX Apr 24 '18 at 16:34
1

Your error is that you simply wrote 12=\fieldl instead of 13=\fieldl.

However, your table could be improved not using vertical rules with booktabs or, much better, not using vertical rules at all.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{csvsimple,longtable,booktabs}
\renewcommand*{\arraystretch}{1.4}  

\begin{filecontents*}{table7.csv}
    A,B,C,D,E,F,G,H,I,J,K,L,M
    Germany,GDP,X,X,,,,,,,X,,X
    France,GDP,X,X,,X,,X,,,X,,X
\end{filecontents*}

\begin{document}
    You simply wrote \verb|12=\fieldl| instead of \verb|13=\fieldl|.

    But vertical rules with \verb|booktabs| don't go well together. 
    If you want vertical rules, don't use \verb|\toprule|, \verb|\midrule|
    or \verb|\bottomrule| (and increase \verb|\arraystretch|): 

    \csvreader[
    respect all,%
    longtable={|p{2cm}|p{2cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|},
    separator=comma,
    table head=\caption{List with data.\label{tab:norules}}\\
    \hline\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \hline\endfirsthead
    \hline\endfoot,
    late after line=\\,
    ]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,13=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}

    But it is much better to get rid of the vertical rules:

    \renewcommand*{\arraystretch}{1.2}  
    \csvreader[
    respect all,%
    longtable={*{2}{p{2cm}}*{11}{p{0.3cm}}},
    separator=comma,
    table head=\caption{List with data.\label{tab:norules}}\\
    \toprule\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \midrule\endfirsthead
    \bottomrule\endfoot,
    late after line=\\,
    ]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,13=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}

\end{document}

enter image description here

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.