3

I have the following CSV dow_distribution.csv file:

DoW,ANZ Vol.,CBA Vol.,MQG Vol.,NAB Vol.,WBC Vol.,AORD Vol.,Total Vol.
Monday,3.63,1.93,0.88,3.14,3.56,457.56,470.7
Tuesday,4.11,2.12,0.92,3.64,4.07,520.05,534.92
Wednesday,4.36,2.26,1.02,3.86,4.3,543.45,559.25
Thursday,4.56,2.46,1.07,4.22,4.44,547.04,563.79
Friday,2.47,1.36,0.63,2.22,2.33,292.65,301.67
Saturday,0,0,0,0,0,0,0
Sunday,1.58,0.86,0.35,1.4,1.56,194.2,199.96

I want to create a multiple bar charts from this csv file. I've come across the csvsimple package, which makes creating tables from CSV files very easy.

Question:

I can't seem to find a way of creating a caption when I use this package, how can I create a caption for a table created by using \csvautotabular{}?

Code:

\documentclass[a4paper,14]{report}
\usepackage[utf8]{inputenc}  
\usepackage{csvsimple}
\usepackage{geometry}
\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\begin{document}

\csvautotabular{dow_distribution.csv}

\end{document}

Desired Output: enter image description here

0

1 Answer 1

5

Like you would any other table, place the \csvautotabular in a table environment and add a \caption. I think I'd suggest loading the booktabs package and using \csvautobooktabular by the way.

To specify different column types, I think you have to use \csvreader, which is a bit more work. I couldn't make it work with \csvautotabular at least, though it's possible I just did something wrong.

By the way, 14 is not a valid option to the documentclass (neither is 14pt), so you get a warning about an "unused global option" if you don't remove it.

enter image description here

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}  
\usepackage{booktabs} % added
\usepackage{csvsimple}
\usepackage{geometry}
\geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\begin{document}

\begin{table}
\centering
\csvreader[
  tabular=|r*{7}{|c}|,
  table head= \hline DoW & ANZ Vol. & CBA Vol. & MQG Vol. & NAB Vol. & WBC Vol. & AORD Vol. & Total Vol. \\ \hline,
  late after last line=\\\hline,
]{dow_distribution.csv}{}%
{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii}

\caption{Foo}
\end{table}

\begin{table}[h]
\centering
\csvautobooktabular{dow_distribution.csv}
\caption{Foo}
\end{table}

\end{document}
3
  • How would one modify the borders of the table to look like the one in my question (ie include vertical lines)? Also how would one make the whole table center aligned with the exception of the days of the week beinf right aligned? Many thanks in advance!
    – 3kstc
    May 11, 2018 at 7:48
  • @3kstc The lack of vertical lines comes from using \csvautobooktabular instead of \csvautotabular. Just remove the book and you're back to what you had, though I think it looks much better without the vertical lines. May 11, 2018 at 7:53
  • @3kstc Don't know offhand how to change the alignment of the columns, will have to browse the manual a bit. May 11, 2018 at 7:54

You must log in to answer this question.

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