1

I tried to hack this here for a larger case but it is firing errors. What is causing the too many columns error and is Pgfplots ideal for this kind of table generation?

enter image description here

Goal: table that I am trying to reproduce with Pgfplots

enter image description here

MWE with pgfplots Error: Table 'anu1.csv' appears to have too many columns in line

\documentclass[11pt,english]{article}

\usepackage{pgfplotstable}
\usepackage{filecontents,booktabs}
\pgfplotsset{compat=1.9}% supress warning

\begin{document}

\begin{filecontents*}{anu1.csv}
Country, Total, <100 miles from Caspian Sea, Major Activities
Azerbaijan, 2, 2, SOCAR runs gas processing plants for Caspian basin fields including Shah Deniz.
Iran, 40, 0, -- 
Kazakhstan, 14, 3*, TengizChevrOil runs a gas processing plant to pick up associated gas from the Russia, 37, 2, Gazprom and LUKOil run gas processing plants for natural gas from the large AstrakhTurkmenistan, 2, 0, Iranian company Ramshir currently building processing plant for Korpezhe field
Uzbekistan, 4, 0, --
\end{filecontents*}


\begin{center}

\pgfplotstabletypeset[
    string type, 
    col sep=comma, 
    columns={Country,Total,<100 miles from Caspian Sea,Major Activities},
    columns/Country/.style={column type=l},
    columns/Total/.style={column type=l},
    columns/<100 miles from Caspian Sea/.style={column type=l},
    columns/Major Activities/.style={column type=l},
    every head row/.style={before row=\toprule,after row=\cmidrule(lr){1-1}\cmidrule(lr){2-2}},
    every last row/.style={after row=\bottomrule}
    ]{anu1.csv}

\end{document}
  • @PeterGrill The Goal in bold is the image, it is the table that I am trying to reproduce :) – hhh Nov 10 '14 at 5:22
2

Since you have really wide data you need to use a column type that allwos for wrapping. An easy way to do that is t use the array package to define two new column types as I have below. The C column type is used on the < 100 miles... column as the header was really wide. The P column type is used to ensure that the last column is wrapped across multiple lines:

enter image description here

Notes:

  • I would have thought the the last column of row 1 needed to be wrapped in a {} since there was a comma in the text, but it appears to work without that.

Code:

\documentclass{article}

\usepackage{pgfplotstable}
%\usepackage{showframe}
\usepackage{booktabs}
\usepackage{colortbl}
\pgfplotsset{compat=1.9}% supress warning

\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.5cm}}
\newcolumntype{P}{>{\raggedright\arraybackslash}p{5.0cm}}

%\usepackage{filecontents}% <-- commend out to prevent overwrite
\begin{filecontents*}{anu1.csv}
Country,       Total, $<100$ miles from Caspian Sea,                             Major Activities
Azerbaijan,    2,     2,  SOCAR runs gas processing plants for Caspian basin fields, including Shah Deniz.
Iran,          40,    0,  --
Kazakhstan,    14,    3*, TengizChevrOil runs a gas processing plant to pick up associated gas from the 
Russia,        37,    2,  Gazprom and LUKOil run gas processing plants for natural gas from the large Astrakh
Turkmenistan,  2,     0,  Iranian company Ramshir currently building processing plant for Korpezhe field
Uzbekistan,    4,     0,  -- 
\end{filecontents*}

\begin{document}

\noindent
\pgfplotstabletypeset[
    string type, 
    col sep=comma, 
    columns={Country,Total,$<100$ miles from Caspian Sea,Major Activities},
    columns/Country/.style={column type=l},
    columns/Total/.style={column type=c},
    columns/$<100$ miles from Caspian Sea/.style={column type=C},
    columns/Major Activities/.style={column type=P},
    every head row/.style={
        before row=\toprule,
        after row=
            \cmidrule(lr){1-1}
            \cmidrule(lr){2-2}
            \cmidrule(lr){3-3}
            \cmidrule(lr){4-4}
    },
    every last row/.style={after row=\bottomrule}
    ]{anu1.csv}

\end{document}
  • Nice! You can do almost anything with pgfplots :D – hhh Nov 10 '14 at 6:24
  • Yeah you can, but personally I'd reserve that honor for \tikzmark, as I have abused that sooooo many times on TeX.SE. :-) – Peter Grill Nov 10 '14 at 6:26
  • Hmm... I have never used \tikzmark, interesting. It is just for drawing arrows and pointing things? – hhh Nov 10 '14 at 6:47
  • @hhh: Well that is where it is often used, but in general it is useful when you want to refer to where on the page some text or graphic got placed. – Peter Grill Nov 10 '14 at 7:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.