pgfplotstable 和 _{some text} 或 ^{such text} 在字符串类型列中

pgfplotstable 和 _{some text} 或 ^{such text} 在字符串类型列中

因此,这是使该表正常工作所需的第二个问题:

我正在使用这个:

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

因此,当我在表格的第二行(第三行加上标题)中放入一些带有 的条目以x_{some text}制作索引时,就会出现问题。在早期版本中,我只是用s
包裹单元格内容,它甚至无法输入像 这样的内容。我想要那种没有 的单位样式... 最大的问题是我的系统不会给我报告或任何提示来解决这个问题。有人有想法吗? 提前感谢您的努力。$replace string*^{-1}/

答案1

您对问题的分析不正确。引发错误的单元格包含

ANPP_{Stems}

并且位于具有规范的列中

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

如果你用以下代码替换条目

ANPP_1

该表编译起来没有问题(除了缺少参考书目)。另一方面,如果你写

ANPP{Stems}

您确实会收到错误,所以是花括号导致了这个问题。

除了使用string replace*,您还可以直接在列样式中使用预处理器,如下所示:

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

或者你可以将mathrm其与你的math风格结合起来:

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

示例输出

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

相关内容