我是 LaTeX 新手,现在正在使用 TeXworks 编译文档。我现在正尝试在文档中创建 CSV 表格,虽然我成功了,但代码中一定有一些小错误,我就是找不到(相信我,我找了好几个小时)。
我的代码如下:
\documentclass[9pt]{article}
% Load packages
%************************************************************
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=0.75in,rmargin=0.75in}
\usepackage{textcomp}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{rotating}
\usepackage{datatool} % Allows importing tables
\usepackage{enumerate} % Allows latin I option
\renewcommand{\tabcolsep}{2pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\DTLsetseparator{,}
\DTLloaddb{tarea}{table_test.csv}
\begin{table}
\caption{Area}
\centering
\DTLdisplaydb{tarea}
\end{table}
\end{document}
Latex 给出以下错误:
错误 1
undefined
34
! Argument of \@dtl@trim has an extra }.
<inserted text>
\par
l.34 \beginstable}
错误 2
undefined
?
LaTeX Warning: Unused global option(s):
[9pt].
错误 3
undefined
?
Package geometry Warning: The marginal notes overrun the paper.
Add 21.7975pt and more to the right margin.
答案1
我可以建议你使用 pgfplotstable 吗?它非常适合处理 CSV 文件,并且给你很多控制权。这是一个很好的例子:
\documentclass[oneside]{article}
\usepackage{pgfplotstable}
% recommended:
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}
\pgfplotstableset{col sep=comma}
\begin{document}
\begin{table}
\centering
\pgfplotstabletypeset[%
% Sort the values
sort, sort key=error2,
%
% The columns to be printed
columns={dof,error1,{grad(log(dof),log(error2))}},
%
% Columns styles
columns/error1/.style={
% Name
column name=$L_2$,
% Notation and padding
sci,sci zerofill, sci subscript,
precision=3},
columns/dof/.style={
sci, sci sep align,
column name=\textsc{Dof}},
columns/{grad(log(dof),log(error2))}/.style={
column name=slopes $L_2$,
fixed, fixed zerofill,
% Align decimal deparators
dec sep align,
precision=1},
%
% Some colors.
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule},
]{data.csv}
\end{table}
\end{document}