tabularx 和 pgfplotstableset

tabularx 和 pgfplotstableset

我想在乳胶中制作一个类似于这个的表格(从 pdf 中提取):

在此处输入图片描述

我曾尝试过pgfplotstable在 csv 表中具有值:

\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} % 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{document}


\pgfplotstableset{
  debug=true,
  string type,
  header=false,
  col sep=comma,
  row sep=\\,
  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)
  every row 0 column 0/.style={ postproc cell content/.style={@cell content=\cellcolor{white}} }, %suppress first cell (pos 0,0)
  column type/.add={}{ @{\hspace{0.2em}} }, % set space between columns
  columns/0/.style={ column type/.add={>{\columncolor[gray]{.8}}}{} },  % first column color
  columns/1/.style={ column type/.add={>{\columncolor[gray]{.95}}}{} }, % second column color
  columns/2/.style={ column type/.add={>{\columncolor[gray]{.95}}}{}  }, % third column color  
}

\pgfplotstabletypeset[]{capabilities.csv} % filename/path to file

\end{document}

结果不符合纸张尺寸(A4),因此我尝试添加表格型使用以下命令修改表:

  begin table={
    \begin{tabularx}{
        \textwidth}{a a a}
  },
  end table={
    \end{tabularx}
  },

但它不兼容(未定义控制序列) 使用列修饰符:

  column type/.add={}{ @{\hspace{0.2em}} }, % set space between columns
  columns/0/.style={ column type/.add={>{\columncolor[gray]{.8}}}{} },  % first column color
  columns/1/.style={ column type/.add={>{\columncolor[gray]{.95}}}{} }, % second column color
  columns/2/.style={ column type/.add={>{\columncolor[gray]{.95}}}{}  }, % third column color  

我想知道是否有其他方法可以让表格适应纸张大小。我正在考虑不使用pgfplotstable,但我喜欢将表格数据与表示分开的想法。

注意:如需示例,请使用此功能.csv桌子:

,Previous Meshlium version,New Meshlium
CPU cores,1,4
CPU architecture,32 bits,64 bits
CPU frequency,500 MHz,1 GHz
RAM,256 MB DDR,2 GB DDR3
Storing,Compact Flash 8 GB,SSD disk 16 GB
Linux Kernel,2.6,3.16
Simultaneous cloud services,2-4,15-20
Boot time,\(\approx\) 2 minutes,Less than 1 minute
WiFi,a/b/g (up to 54 Mbps),a/b/g/n (up to 144 Mbps)
Cellular,Up to 7.2 Mbps downlink (SIM5218) Up to 384 kbps downlink (SIM5215),Up to 42 Mbps downlink
Antenna connectors,4,10
RF module sockets,1,2
Geolocation,GPS,GPS + GLONASS
Root access,Yes,No
Power consumption,\(\approx\) 10 W,\(\approx\) 15 W (depending on number of radios)
Enclosure (mm),210 x 190 x 0, 30 x 220 x 80
Certifications,CE / FCC / IC,CE (Europe) / FCC (US) / IC (Canada) / ANATEL (Brazil) / RCM (Australia) / PTCRB (US) / AT\&T (US)

提前感谢。

答案1

最后,按照@TeXnician 的建议,这是制作类似表格的代码:

\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} % 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}
  ,Previous Meshlium version,New Meshlium
  CPU cores,1,4
  CPU architecture,32 bits,64 bits
  CPU frequency,500 MHz,1 GHz
  RAM,256 MB DDR,2 GB DDR3
  Storing,Compact Flash 8 GB,SSD disk 16 GB
  Linux Kernel,2.6,3.16
  Simultaneous cloud services,2-4,15-20
  Boot time,\(\approx\) 2 minutes,Less than 1 minute
  WiFi,a/b/g (up to 54 Mbps),a/b/g/n (up to 144 Mbps)
  Cellular,Up to 7.2 Mbps downlink (SIM5218) \(\linebreak\)Up to 384 kbps downlink (SIM5215),Up to 42 Mbps downlink
  Antenna connectors,4,10
  RF module sockets,1,2
  Geolocation,GPS,GPS + GLONASS
  Root access,Yes,No
  Power consumption,\(\approx\) 10 W,\(\approx\) 15 W (depending on number of radios)
  Enclosure (mm),210 x 190 x 0, 30 x 220 x 80
  Certifications,CE / FCC / IC,CE (Europe) / FCC (US) / IC (Canada) / ANATEL (Brazil) / RCM (Australia) / PTCRB (US) / AT\&T (US)
\end{filecontents*}



\begin{document}


\pgfplotstableset{zerofill}
\pgfplotstabletypeset[
  reset styles,
  debug=true,
  string type,
  header=false,
  col sep=comma,
  row sep=newline,
  every first row/.style={
    before row={
      \rowcolor[gray]{0.8} % first row color
      \vspace{0.2em} % first row space between rows
    }
  },
  column type=,
  begin table={
    \begingroup\renewcommand{\arraystretch}{1.2}
    \begin{tabularx}{\textwidth}{
        >{\cellcolor[gray]{.8}}l@{\hskip 1.4em}
        >{\columncolor[gray]{.95}}X@{\hskip 1.4em}
        >{\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)
  every row 0 column 0/.style={ postproc cell content/.style={@cell content=\cellcolor{white}} }, %suppress first cell (pos 0,0)    
]{matrix.csv}

\end{document}

相关内容