我有以下 CSVdow_distribution.csv
文件:
dow,ANZ Volume,BHP Volume,CBA Volume,MQG Volume,NAB Volume,QAN Volume,RHC Volume,TLS Volume,WBC Volume,WOW Volume,AORD Volume,Total Volume
Monday,3.63,6.64,1.93,0.88,3.14,5.77,0.23,19.89,3.56,1.57,457.56,504.81
Tuesday,4.11,7.74,2.12,0.92,3.64,7.04,0.25,22.3,4.07,1.8,520.05,574.05
Wednesday,4.36,8.14,2.26,1.02,3.86,7.58,0.26,23.82,4.3,1.91,543.45,600.96
Thursday,4.56,8.32,2.46,1.07,4.22,7.3,0.25,24.05,4.44,2.05,547.04,605.76
Friday,2.47,4.61,1.36,0.63,2.22,3.76,0.13,13.38,2.33,1.02,292.65,324.58
Saturday,,,,,,,,,,,,0
Sunday,1.58,2.88,0.86,0.35,1.4,2.46,0.09,8.91,1.56,0.76,194.2,215.06
我想将其处理成适合我的页面宽度的表格。
我已经尝试过以下 - 并且一直在阅读csvsimple 包去纠正但却很困难。
\documentclass[a4paper,14]{report}
\usepackage[utf8]{inputenc} % Commented out due to Cautionary error.
\usepackage{csvsimple}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\begin{document}
\csvautotabular{dow_distribution.csv}
\end{document}
期望输出:
答案1
该\csvautotabular
宏仅用于快速可视化。它不适用于生产代码。此处,\csvreader
或\csvloop
允许自定义。
我对您的餐桌有两点建议。
第一个将表格列设置为固定宽度,9mm
这会导致标题自动断开。
第二个借助包graphicx
和一个小的辅助宏将长标题文本旋转 90 度\myrot
。
\documentclass[a4paper,14]{report}
\usepackage[utf8]{inputenc} % Commented out due to Cautionary error.
\usepackage{csvsimple,graphicx}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\def\myrot#1{\rotatebox{90}{\csname csvcol#1\endcsname\ }}
\begin{document}
{\small\tabcolsep1.4mm%
\csvreader[
tabular=|r|*{12}{p{9mm}}|,
nohead,column count=13,
table head=\hline,
late after first line=\\\hline,
table foot=\hline]{dow_distribution.csv}%
{}%
{\csvlinetotablerow}
}
\bigskip
\csvreader[
tabular=|r|*{12}{c}|,
nohead,column count=13,
table head=\hline,
late after first line=\\\hline,
table foot=\hline]{dow_distribution.csv}%
{}%
{\csviffirstrow{%
\csvcoli & \myrot{ii} & \myrot{iii} & \myrot{iv} & \myrot{v} & \myrot{vi} & \myrot{vii}
& \myrot{viii} & \myrot{ix} & \myrot{x} & \myrot{xi} & \myrot{xii} & \myrot{xiii}
}{\csvlinetotablerow}}
\end{document}
得出: