Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am new in latex and I have some issues. I want to read a .csv file in latex to create a table, but I don't know how. I heard that datatool package can do this, but I don't know how to use it.

My input is smth like this:

,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15,w16,w17,w18,w19,w20,w21,w22,w23,w24
,25,23,13,14,15,39,36,4,37,11,26,13,34,39,40,22,33,32,9,5
,56,31,45,31,38,41,59,26,,44,52,33,,42,,28,51,41,28,36

Thank you!

Update:

I think I found the answer of how to create a table based on a csv file. The name of the packages is actually csvtools.

share|improve this question

migrated from stackoverflow.com May 16 '12 at 23:36

This question came from our site for professional and enthusiast programmers.

2  
csvtools is the old version of the package. The current version is indeed called datatool. –  Alan Munn May 16 '12 at 23:54

1 Answer 1

up vote 12 down vote accepted

Assuming that the first row is the name of the columns, then you simply need to load the database via \DTLloaddb{myDB}{MyData.csv} where the file MyData.csv contains the contents as shown above, and the you can use the internal function \DTLdisplaydb{myDB} to print it as a table.

This table is very wide so I used the geometry package to extend the width of the paper. Here is the first few columns of the table:

enter image description here

If the first row is not the header row, then you can specify the key for each column as:

\DTLloaddb[noheader,keys={,ColW5, ColW6, ColW7}]{myDB}{MyData.csv}

where only keys for the first three columns have been included.

Code:

\documentclass{article}
\usepackage[showframe,paperwidth=32cm]{geometry}
\usepackage{datatool}

\begin{document}
    \DTLloaddb{myDB}{MyData.csv}
    \noindent\DTLdisplaydb{myDB}
\end{document}
share|improve this answer
    
Thank you so much your the tips. –  Ion Morozan May 16 '12 at 23:10
    
And if I don't want to take in consideration the first row? Because it has to be like w5 -> 5 to 6am. –  Ion Morozan May 17 '12 at 10:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.