I have a big table that I want to put into my latex Document. The problem that I have is that the header line (the top line) for the column names is too long. This is my state.csv file

game id,start,dimensions,number of players,error type,survived rounds,avg iter dur,max iter dur
1,,"(46, 58)",6,____,3,0.0189638150252525,0.070585
2,,"(73, 54)",3,____,59,0.0081690392435849,1.142459
3,,"(62, 65)",3,____,107,0.0101505997288269,2.223196
4,,"(44, 75)",5,____,25,0.0157099498952178,2.771
5,,"(41, 41)",3,____,63,0.0062615696206158,1.012879
6,,"(42, 71)",5,____,63,0.006719767371205704,1.936

For example: Latex will write number of players in one line but I want that latex inserts a linebreak after number or of in order to make the table not so wide. I also looked into the csvmanual but I did not find any suggestion on how to deal with this. https://osl.ugr.es/CTAN/macros/latex/contrib/csvsimple/csvsimple.pdf

With \csvautotabular[]{state.csv} the table looks like this: The table is longer than the paper and the values are not inside the table

As you can see the table is longer than the paper width and the values inside the table are missing. How can I fit the table nicely into my Latex document?

3 Answers 3


One way is to play with the tabular environment rather than csv as you can determine easily the size of your cells:




game id&start&dimensions&number of players&error type&survived rounds&avg iter dur&max iter dur


will give you something like enter image description here

Then you can play with the size that it fits exactly what you want. You can customize it easily. Then you can enter every line of your data. For long data, you can also use \usepackage{array}

A tutorial for the tabular environment:https://www.overleaf.com/learn/latex/tables

  • Hey, thank you for your reply. It is correct to resize the column width with the p{1.5cm} option but how can i then automatically read the .csv file in with these appropriate width options that i configured?
    – primeseas
    Jan 12, 2021 at 11:47

Your .csv file is badly formatted. First of all the _ symbol cannot be used in text mode. I changed it to -. Secondly, according to the csvsimple documentation:

Every line of a processable CSV file has to contain an identical amount of comma separated values. The curly braces {} of TeX groups can be used to mask a block which may contain commas not to be processed as separators.

The mwe example below shows two of the many solutions made possible by the csvsimple package.


game id,start,dimensions,number of players,error type,survived rounds,avg iter dur,max iter dur
1,,{(46, 58)},6,--,3,0.0189638150252525,0.070585
1,,{(46, 58)},6,--,3,0.0189638150252525,0.070585
2,,{(73, 54)},3,--,59,0.0081690392435849,1.142459
3,,{(62, 65)},3,--,107,0.0101505997288269,2.223196
4,,{(44, 75)},5,--,25,0.0157099498952178,2.771
5,,{(41, 41)},3,--,63,0.0062615696206158,1.012879
6,,{(42, 71)},5,--,63,0.006719767371205704,1.936


\section{A first simple solution}


\section{Another (not so simple) solution}

table head=\toprule \bfseries game id & \bfseries start & \bfseries dimensions & \bfseries number of players
           & \bfseries error type & \bfseries survived rounds & \bfseries  avg iter dur & \bfseries max iter dur\\\midrule, 
table foot=\bottomrule]

  • Thank you Ivan, that helped me.
    – primeseas
    Jan 13, 2021 at 19:46

I have found a workaround for your header using the makecell package. To insert a manual line break you can use the \thead command from this package. An MWE based on your csv file is provided here:



             \thead{game\\id} & start & dimensions & \thead{number of\\players} & \thead{error\\type} & \thead{survived\\rounds} & \thead{avg iter\\ dur} & \thead{max iter\\ dur}\\
             \csvreader[late after line=\\\hline] {state.csv}{game id = \gameId, start = \start, dimensions = \dimensions, number of players = \numberOfPlayers, error type = \errorType, survived rounds = \survivedRounds, avg iter dur = \avgIterDur, max iter dur = \maxIterDur}{\gameId & \start & \dimensions & \numberOfPlayers & \errorType & \survivedRounds & \avgIterDur & \maxIterDur}

The output looks as follows with your csv file:

enter image description here

But I couldn't find why the whole csv file is not imported. Also, the borders (vertical lines) in the 2nd row haven't appeared. I will edit the answer if I can find a solution to this.

Edit: As per the mentioned edits in the answer of Ivan, I edited your csv file and got the desired result as follows:

After Editing the csv file

  • 1
    The .csv file is not imported because it is badly formatted, as said in my answer
    – Ivan
    Jan 12, 2021 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .