1

I would like to create custom tables from .csv files. By custom I mean, that I only want LaTex to read in the body of the table, i.e. "a & b & ... \ ..." but I want to write my own header and formating around it (I know names and number of columns). I am aware of the package datatool, but this seems to only provide a function for loading an entire table (with a single header row constructed from variable names). I need to have multiple header rows for hierarchical grouping of columns however. Manual input of the numbers is not really an option - too many numbers ;)

How would I best do such a thing in LaTex?

  • Welcome to TeX.SE. t would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. And include some sample data, along with some details as to the hierarchical grouping that you are referring to. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Nov 7 '14 at 7:59
  • My recent answer How to print addresses shows how to read a CSV without headers. Perhaps that will get your problem solved. If not, please make an attempt to show exactly what the problem is. – Peter Grill Nov 7 '14 at 8:01
  • 1
    Using the datatool package, it is possible to add header rows above the default one by redefining \dtldisplaystarttab. On long tables, this will be added above the header line on all the pages. Other hooks are available, see p49 of the documentation. – TonioElGringo Nov 7 '14 at 8:15
1

Thank you @TonioElGringo, that does exactly what I was looking for. Here an example for a 3 column .csv file.

\documentclass{article}
\usepackage{datatool}
\usepackage[margin=1in]{geometry}
\begin{document}
\DTLloaddb{stores}{scientists.csv}
\renewcommand{\dtldisplaystarttab}{\multicolumn{3}{c}{I am what I was looking for!}\\}
\DTLdisplaydb{stores}
\end{document}

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.