我正在尝试通过 CSV 和 csvreader 显示一个有两行 13 列的表格。
从内容中可以看出,两行的最后一列有两个 X。但是,它们没有显示在“M”列中(见图)。我做错了什么?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple,longtable,booktabs}
\begin{filecontents*}{table7.csv}
A,B,C,D,E,F,G,H,I,J,K,L,M
Germany,GDP,X,X,,,,,,,X,,X
France,GDP,X,X,,X,,X,,,X,,X
\end{filecontents*}
\begin{document}
\csvreader[
respect all,%
longtable={|p{2cm}|p{2cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|},
separator=comma,
table head=\caption{List with data.\label{tab:mytable7}}\\
\toprule\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \midrule\endfirsthead
\bottomrule\endfoot,
late after line=\\,
]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,12=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}
\end{document}
答案1
您的错误在于您只是简单地写了12=\fieldl
而不是13=\fieldl
。
但是,如果不使用垂直线,您的表格可以得到改进,booktabs
或者更好的是,根本不使用垂直线。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{csvsimple,longtable,booktabs}
\renewcommand*{\arraystretch}{1.4}
\begin{filecontents*}{table7.csv}
A,B,C,D,E,F,G,H,I,J,K,L,M
Germany,GDP,X,X,,,,,,,X,,X
France,GDP,X,X,,X,,X,,,X,,X
\end{filecontents*}
\begin{document}
You simply wrote \verb|12=\fieldl| instead of \verb|13=\fieldl|.
But vertical rules with \verb|booktabs| don't go well together.
If you want vertical rules, don't use \verb|\toprule|, \verb|\midrule|
or \verb|\bottomrule| (and increase \verb|\arraystretch|):
\csvreader[
respect all,%
longtable={|p{2cm}|p{2cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm}|},
separator=comma,
table head=\caption{List with data.\label{tab:norules}}\\
\hline\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \hline\endfirsthead
\hline\endfoot,
late after line=\\,
]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,13=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}
But it is much better to get rid of the vertical rules:
\renewcommand*{\arraystretch}{1.2}
\csvreader[
respect all,%
longtable={*{2}{p{2cm}}*{11}{p{0.3cm}}},
separator=comma,
table head=\caption{List with data.\label{tab:norules}}\\
\toprule\bfseries A &\bfseries B &\bfseries C &\bfseries D &\bfseries E &\bfseries F &\bfseries G &\bfseries H &\bfseries I &\bfseries J &\bfseries K &\bfseries L &\bfseries M \\ \midrule\endfirsthead
\bottomrule\endfoot,
late after line=\\,
]{table7.csv}{1=\fieldx,2=\fielda,3=\fieldb,4=\fieldc,5=\fieldd,6=\fielde,7=\fieldf,8=\fieldg,9=\fieldh,10=\fieldi,11=\fieldj,12=\fieldk,13=\fieldl}{\fieldx&\fielda&\fieldb&\fieldc&\fieldd&\fielde&\fieldf&\fieldg&\fieldh&\fieldi&\fieldj&\fieldk&\fieldl}
\end{document}