我正在尝试重现一个具有多列的表格,如下所示:
我知道我应该使用多列和多行来产生所需的效果。这是我编写的代码:
\documentclass[
english,
a4paper,
10pt,
openany
]{book}
\usepackage{textcomp}
\usepackage{titlesec} % customize title format
\usepackage[margin=1.2cm]{geometry} % customize global margings
\usepackage{caption} % customize figure captions
\usepackage{graphicx}% include graphics
\usepackage{fancyhdr} % customize header and footer
\usepackage[titles]{tocloft} % customize toc
\usepackage{pgfplotstable, tabularx, booktabs, multirow} % Generates table from .csv
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{xcolor, colortbl} % use colors for tables
\usepackage{ifpdf} % customize PDF output
\ifpdf
\usepackage[pdftex,
pagebackref=true,
colorlinks=true,
linkcolor=blue,
unicode
]{hyperref}
\fi
\begin{filecontents*}{matrix.csv}
Max Current supply,\multicolumn{2}{l}{2A}
\multirow{4}{*}{Enclosure},Material,Aluminium
,Dimensions, 300x200x87 mm
,Weight, 2.2 Kg
,External Protection, IP65
Temperature Range,\multicolumn{2}{l}{-20$^\circ$C / 50$^\circ$C}
\end{filecontents*}
\begin{document}
\pgfplotstableset{zerofill}
\pgfplotstabletypeset[
reset styles,
debug=true,
string type,
header=false,
col sep=comma,
row sep=\\,
every first row/.style={
before row={
\vspace{0.2em} % first row space between rows
}
},
column type=,
begin table={
\begingroup\renewcommand{\arraystretch}{1.2}
\begin{tabularx}{\textwidth}{
>{\columncolor[gray]{.8}}l@{\hskip 1.4em}
>{\columncolor[gray]{.95}}X
>{\columncolor[gray]{.95}}X
}
},
end table={\end{tabularx}\endgroup},
every nth row={1}{ before row={\vspace{0.2em}} }, % set space between rows
every head row/.style={ output empty row }, % suppress printing head row (numbers)
]{matrix.csv}
\end{document}
使用以下命令进行编译:
latexmk -pdf -pdflatex="pdflatex --synctex=1 --file-line-error" -use-make myfile.tex
没有产生任何输出并且错误消息表明列数不匹配:
...PGFPlots found that the number of columns is larger than the previously determined number of columns...
我知道问题在于使用多列,因为如果我删除多列命令(并在末尾添加一个新列),它会产生以下输出:
有人可以告诉我为什么多列不能与 pgfplotstabletypeset 一起使用吗?以及是否有解决方案可以使用多列或其他替代方法来生成像示例那样的表格。
提前致谢!