[Tex/LaTex] Creating a Table caption with csvsimple package using \csvautotabular{}

csvsimple

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

Best Answer

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}