3

So this is the second question I need to ask to get this table working:

I'm using this:

\documentclass{article}
\usepackage[margin=1cm,a3paper]{geometry}
\usepackage{siunitx}
\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage{graphicx} 
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{pgfplotstable}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{makecell}
\usepackage[style=authoryear-comp,maxbibnames=25, maxcitenames=2,backend=biber]{biblatex}
%some bib libraries and style commands
\usepackage{booktabs} 
\pgfplotsset{compat=1.12}
\usepackage{multicol}
\usepackage{hyperref}

\usepackage[babel,german=quotes]{csquotes}
\usepackage{array}

\pgfplotstableset{every head row/.style={before row=\toprule, after row=\midrule\endhead},
every last row/.style={after row=\bottomrule}}

\begin{document}


\begin{landscape}%
\pgfplotstabletypeset[begin table=\begin{longtable},end table=\end{longtable},
header=true, col sep=comma, use comma, row sep=newline,
math/.style={preproc cell content/.append style={/pgfplots/table/@cell content/.add={$}{$}},},
%0
columns/Autor/.style={string replace*={##1}{\textcite{##1}},column name={Quelle}, string type, column type =l},
%1
columns/Ort/.style={column name={Ort}, string type, column type = l},
%2
columns/Longitude/.style={column name={Longitude},string replace*={##1}{\ang{##1}}, string type, column type=r},
%3
columns/Latitude/.style={column name={Latitude},string replace*={##1}{\ang{##1}}  , string type, column type=r},
%4
columns/Wert/.style={, column type=r, dec sep align, fixed,precision=2,column name={\makecell{Werte}},clear infinite,},
%5
columns/Einheit/.style={column name={[Einheit]}, string type, column type=l,math},
%6
columns/Beschreibung/.style={column name=Beschreibung,string replace*={##1}{{\mathrm{##1}}}, string type, column type=l,math},
%7
columns/Dichte/.style={, column type=r, dec sep align,fixed,precision=2,column name={\makecell[c]{$\rho$ \\ $[kg \cdot m^{-3}]$}},clear infinite },
%8
columns/DichteQuelle/.style={string replace*={##1}{\textcite{##1}},column name={Quelle $\rho$}, string type, column type =l},
%9
columns/l/.style={column name={$l$}, precision=2, column type=r,clear infinite },
%10
columns/NAI/.style={,fixed,precision=2, column type=r , dec sep align,column name={\makecell[c]{NAI \\ $[m^3\cdot ha^{-1}]$}},clear infinite },
%11
columns/Baumarten/.style={column name={Spezies}, string replace*={##1}{\textit{##1}}, string type, column type =l}
]
{
Autor,Ort,Longitude,Latitude,Wert,Einheit,Beschreibung,Dichte,DichteQuelle,l,NAI,Baumarten
VasconcelosEtAl2012,Brasilien ,-1;19;0,+47;57;0,14.45,Mg \ ha^{-1} year^{-1},ANPP,0.704,NogueiraEtAl2005,0.5,4.928,-
BernierEtAl2007,Chibougamau Quebec,+49;41;31.2,+74;25;55.2,2090,kg \ ha^{-1}  yr^{-1},ANPP_{Stems},0.45,AseevaEtAl2014,NaN,4.644444444,Picea mariana  (Black Spruce) 
}

\end{landscape}%

\end{document}

So the problem occurs when I put in the second (third with head) row of the table some entry with x_{some text} to make indices.
In an earlier version, where I just wrapped the cell content with $s with replace string* it didnt even work for input like ^{-1}. I want to have that style of Units without /...
The biggest problem is that my system wont give me an report or any hint to solve that. Has anyone an idea?
Thanks in advance for your effort.

1
  • well, for everybody how comes across this question, use the string replace key, if needed multiple times. Is the only solution or workaround I found.
    – lanthanoid
    Jun 18, 2015 at 15:02

1 Answer 1

3

Your analysis of the problem is not correct. The cell throwing the error contains

ANPP_{Stems}

and is in a column with specification

columns/Beschreibung/.style={column name=Beschreibung,
   string replace*={##1}{{\mathrm{##1}}}, string type, column type=l,math},

If you replace the entry with

ANPP_1

the table compiles without problem (apart from missing bibliography references). On the other hand if you write

ANPP{Stems}

you do get an error, so it is the curly brackets that are causing this.

Rather than using string replace*, you can directly use the preprocessor in the column style as follows:

 preproc cell content/.append style={@cell content={\mathrm{##1}}}

or you could make a mathrm style combining this with your math style:

mathrm/.style={preproc cell content/.append style
                ={@cell content={$\mathrm{##1}$}}}

Sample output

\documentclass{article}

\usepackage[T1]{fontenc}

\usepackage{pgfplotstable}
\usepackage{tabu}
\usepackage{longtable}

\usepackage{booktabs} 
\pgfplotsset{compat=1.12}

\pgfplotstableset{every head row/.style={before row=\toprule, after row=\midrule\endhead},
every last row/.style={after row=\bottomrule}}

\begin{document}

\pgfplotstabletypeset[begin table=\begin{longtable},end table=\end{longtable},
  header=true, col sep=comma, use comma, row sep=newline,
  math/.style={preproc cell content/.append style
                ={/pgfplots/table/@cell content/.add={$}{$}}},
  columns/Beschreibung/.style={column name=Beschreibung,
    preproc cell content/.append style={@cell content={\mathrm{##1}}},
    string type, column type=l,math}]
{Beschreibung
ANPP
ANPP_{Stems}
}

\pgfplotstabletypeset[begin table=\begin{longtable},end table=\end{longtable},
  header=true, col sep=comma, use comma, row sep=newline,
  mathrm/.style={preproc cell content/.append style
                ={@cell content={$\mathrm{##1}$}}},
  columns/Beschreibung/.style={column name=Beschreibung,
    string type, column type=l,mathrm}]
{Beschreibung
ANPP
ANPP_{Stems}
}


\end{document}
2
  • Hi, thank you for providing your solution, and correcting my bad english. In my document I'm not using an inline input, I'm using an csv which is generated by MSOffice 2013 ,and I didn't wont to post it here. I also don't want to mess around with curly brackets in the MS Office-sheet. So I use the string replace key for every critical expression in that column.
    – lanthanoid
    Aug 23, 2015 at 20:45
  • Indeed my solution above avoids have to change the input data, but avoids multiple string replaces in your situation. Aug 24, 2015 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .