# Tabularx or Tabulary populated by csvsimple

I am using csvsimple to import table data.

Some cell information is too long and I would like to dynamically manage the column width. I have tried combining the tabularx and tabulary environments with the csvsimple part, but I have been unsuccessful. I am using the memoir document class.

Here is my fixed-width code:

\documentclass[pdftex,10pt,letterpaper, openleft, twoside]{memoir}
\usepackage{array,booktabs,csvsimple,longtable}
...
%Type of column
\newcolumntype{P}[1]{>{#1\hspace{0pt}\arraybackslash}p{75pt}}
...
\begin{document}
...
table foot=\hline, filter equal={\csvcoli}{Something}]{mycsv.csv}%
{}%
{\csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi}\\
\end{document}

• It seems you are out of luck, unless Thomas makes a major upgrade. – user11232 Apr 1 '15 at 5:37
• You can try pgfplotstable which can use tabularx (IIRC). Can you please complete your example to include \documentclass{} and \end{document}? Thanks! – darthbith Apr 1 '15 at 14:37
• darthbith : Change done for the exemple; Would it be possible threw an other way? without tabularx or tabulary? – Simon Boucher Apr 1 '15 at 18:02

It would be difficult to integrate tabularx into the option list of the macro \csvreader; for an environment, there would be ways.

But you can always put a tabularx environment around a \csvreader. The following example shows, how to do this:

\begin{filecontents*}{mycsv.csv}
This,is,my,example
Red,Green,This is some very very long text,This is also some very very long text
Blue,Yellow,This is some even longer text without real content,This is also some even longer text without real content
\end{filecontents*}

\documentclass[pdftex,10pt,letterpaper, openleft, twoside]{memoir}
\usepackage{array,booktabs,csvsimple,longtable,tabularx}

\begin{document}

\begin{tabularx}{\linewidth}{llXX}\toprule
\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D}\\\midrule
\csvreader[late after line=\\\midrule,late after last line=\\\bottomrule]
{mycsv.csv}
{}
{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv}
\end{tabularx}

\end{document}


• Thank you very much again, it worked perfectly. Would it work with tabulary also ?(I suppose yes) – Simon Boucher Apr 2 '15 at 17:53
• @SimonBoucher Yes, here is an example of using it with tabulary. – Thomas F. Sturm Apr 13 '15 at 8:30
• To make the table span over multiple pages it is possible to use \usepackage{ltablex}, which union the advantages of tabularx and longtable. In the actuall table there is no change required, it happens automatically. – meles Feb 3 '16 at 9:17