0

I am trying to reproduce a table with multicolumns like this one:

multiple columns table

I understand that I should use multicolumn and multirow for producing the desire effect. This is the code I made:

\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}

Compile using the command:

latexmk -pdf -pdflatex="pdflatex --synctex=1 --file-line-error" -use-make myfile.tex

No output is produced and the error message says that the number of columns don't match:

...PGFPlots found that the number of columns is larger than the previously determined number of columns...

I know the problem is the use of multicolum because if I remove the multicolumn command (and add a new column at the end) it produces this output:

multi row image

Could somebody englight me why is multicolumn not working with pgfplotstabletypeset? and if there is a solution to use multicolumn or other alternative to produce a table like the example.

Thanks in advance!

  • the idea of the package is mostly not to have tex markup in your csv file. It is probably possible to specify the column spans with suitable row specifications in the pgfplotstable setup, but do you need this at all, in your real example do you need to use a csv and then try to apply table markup to it, rather than just write the table directly (which is much easier) If you have a large data file produced by some other software then the package is a useful way to typeset that by tex, but your csv already contains tex markup so is tex specific, so why not just make a latex tabular directly? – David Carlisle Feb 4 '18 at 21:24
  • I like the idea of having the data and the representation apart. It is because I use pgfplotstable package. I understand that should not be latex commands should be in the "data" file, but I see no other way. – esguti Feb 6 '18 at 8:06
  • if you put \multicolumn in to your data file then you have more than anything not separated the data and presentation, then trying to separate the rest of the presentation aspects from the place that you are specifying \multicolumn vastly complicates the coding, for no clear benefit. – David Carlisle Feb 6 '18 at 9:12
  • why are you using -shell-escape here (that should only be used with caution) – David Carlisle Feb 6 '18 at 9:14
  • I am trying to not to put the data part (.csv) in the representation (.tex). If you have any solution, please answer the question. Regarding the -shell-escape is just for executing the example, I don't think is going to make any difference, but thanks for the suggestion. – esguti Feb 6 '18 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.