2

I have automatically generated CSV (pipe-separated) Data, that I want to print as Latex \csvautobooklongtable. I do not know the the amount of columns (they are variable in number from one set of data to the other).

My problem is, that the lines will not break automatically (every line is one overlong line).

Is there any option I have not found to influence the \csvsimple behaviour to make the table fit the page nicely?

\begin{filecontents*}{data.csv}
This|is|autogenerated|material\n
With|variable|number of|columns\n
Zeile 1|2|3|4\n
Zeile 2 (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|diese Zelle viel Text (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|diese eigentlich auch (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|und vor allem diese Zelle hat sehr viel text\n
Zeile 2|2|3|4\n\end{filecontents*}
\documentclass[fontsize=2mm,a4paper]{scrartcl}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\csvautobooklongtable[separator=pipe, respect all, no check column count]{data.csv}
\end{document}
1

If you know the maximum width of the columns, there is a way for a little hack to change the column type of \csvautobooklongtable.

The following code adds an option my column width to set the column width:

\begin{filecontents*}{data.csv}
This|is|autogenerated|material\n
With|variable|number of|columns\n
Zeile 1|2|3|4\n
Zeile 2 (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|diese Zelle viel Text (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|diese eigentlich auch (lore ipsum lore ipsum lore ipsum lore ipsum lore ipsum)|und vor allem diese Zelle hat sehr viel text\n
Zeile 2|2|3|4\n\end{filecontents*}
\documentclass[fontsize=2mm,a4paper]{scrartcl}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage{longtable}

\makeatletter
\csvset{
  my column width/.style={after head=\csv@pretable\begin{longtable}{*{\csv@columncount}{p{#1}}}\csv@tablehead},
}
\makeatother

\begin{document}

\csvautobooklongtable[separator=pipe, respect all, no check column count,
  my column width=1.5cm,
  ]{data.csv}

\csvautobooklongtable[separator=pipe, respect all, no check column count,
  my column width=2cm,
  ]{data.csv}
\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.