# Line-breaking long cell contents when using longtable through datatool

I'm trying to display a table loaded from a CSV file and displaying it like this:

\DTLloadrawdb[]{myDB}{myDB.csv}
\DTLdisplaylongdb[%
caption={myDB caption},%
label={tab:myDB},%
contcaption={myDB (continued)},%
foot={\em Table continued on next page},%
lastfoot={\em End of Table}%
]{myDB}


This works except that one of the columns contain some long text strings that push the rest of the table off of the side of the page.

The datatool documentation says that it is using the longtable environment for this and to look up how to align contents in the longtable documentation, but I can't figure out how to get this to work. I want the table centered on the page and all the cell contents left-aligned and lines broken if there is too much content.

I'm not trying to break the cells across multiple pages, just the cell contents over multiple lines on the same page.

• to allow longtable to break cells you would need to completely re-write it. If there are only two columns use a list environment instead, if there are more it gets harder, you ned to provide a full example – David Carlisle Nov 20 '13 at 12:40
• It sounds like you need a p specifier for the columns that are too wide. In which case, you may need to manually write the \begin{longtable}{...} and \end{longtable} and use \DTLforeach* to write the table rows. – Nicola Talbot Nov 20 '13 at 12:50
• @DavidCarlisle I'm not trying to break the cells across multiple pages, just the contents over multiple lines on the same page. – LJNielsenDk Nov 20 '13 at 13:11
• @NicolaTalbot I'll give that a try in a bit, thanks. – LJNielsenDk Nov 20 '13 at 13:13
• oh in that case p as Nicola said, same as tabular, array and all other similar environments – David Carlisle Nov 20 '13 at 13:36

Looking at the datatool doc (section 5.4) you can have full control over the table column specification if you use \DTLforeach So if your third column needs to be text justified to lines broken to 5cm, you can do something like
\begin{longtable}{llp{5cm}}