我如何创建看起来像这样的表格?
My Title
-------------------------------------------
Type 1 Type 2
---------- ----------
colA colB colC x y colF colG colH z
-------------------------------------------
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
-------------------------------------------
如果我有格式的基表.csv
?即:
colA,colB,colC,x,y,colF,colG,colH,z
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii
我知道csvsimple
和autobooktabular
,在那里可以做
\usepackage{adjustbox}
\usepackage{booktabs,csvsimple}
[...]
\begin{table}[ht]
\begin{adjustbox}{max width=0.9\textwidth}
\csvautobooktabular[table head={\toprule alp & bet & gam & xx & yy & F & G & H & zz \\\midrule}]{csvs/test.csv}
\end{adjustbox}
\caption{blah blah blah etc.}
\label{tab:test}
\end{table}
它用指定的内容覆盖“head”列table head
并创建
-------------------------------------------
alp bet gam xx yy F G H zz
-------------------------------------------
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
aaa bbb ccc ddd eee fff ggg hhh iii
-------------------------------------------
我不禁觉得应该可以使用它来保留文件的标题但插入额外的标题,尽管我似乎不知道如何做。
答案1
诀窍是使用\csvlinetotablerow
包含第一行。
\documentclass{article}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{booktabs,csvsimple}
\begin{document}
\begin{table}[ht]
\begin{adjustbox}{max width=0.9\textwidth}
\csvautobooktabular[table head={\toprule
\multicolumn{3}{c}{Type 1} & & & \multicolumn{3}{c}{Type 2} & \\
\cmidrule{1-3} \cmidrule{6-8} \csvlinetotablerow\\\midrule}]{test2.csv}
\end{adjustbox}
\caption{blah blah blah etc.}
\label{tab:test}
\end{table}
\end{document}