如何使用 longtable 删除 pgfplotstable 中的多重定义标签

如何使用 longtable 删除 pgfplotstable 中的多重定义标签

我需要为longtable可能带有标签的文本添加标题以供引用,但是 SIAM 格式在遇到重复定义的标签时会失败,因为标题重复。有没有简单的方法可以为第一个标题添加标签?

这是 MWE。第一次编译没有问题,但第二次编译出现此错误:

! SIAM Label Error: There were multiply-defined labels. Correct multiply-defined labels.

所需文件 siamltex.sty、siamltex.cls、siamltex.clo 和 siam10.clo 可从以下位置下载:http://www.siam.org/journals/auth-info.php

\documentclass[final]{siamltex}
%\documentclass[a5paper]{article}
\usepackage{pgfplotstable} 
\usepackage{booktabs} 
\usepackage{filecontents}
\usepackage{longtable}

\begin{document}
\begin{filecontents}{testdata.dat}
Idx  Nam Dim Grd
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
\end{filecontents}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},}
I am referencing to the long table~\ref{aLabel}.
\pgfplotstabletypeset[col sep=space,header=true,    
columns={Idx,Nam,Dim,Grd},      % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},every head row/.style={before row={\caption{A caption}\label{aLabel}\\\toprule}, after row=\midrule\endhead}, every last row/.style={after row=\bottomrule}]{testdata.dat}
\end{document}

答案1

longtable允许指定\endfirsthead\endhead。这些命令的用法在文档中显示pgfplotstable第 21 页也一样。

修改如下:

\makeatletter
\pgfplotstabletypeset[col sep=space,header=true,    
columns={Idx,Nam,Dim,Grd},      % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},%
every head row/.append style={%
    typeset cell/.code={%
       \ifnum\c@pgfplotstable@colindex=1\relax
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{
                             \caption{A caption}\label{aLabel}\\\toprule ##1 \gdef\@tempa{\caption*{A caption}\\\toprule ##1&} &}%
       \else
        \ifnum\c@pgfplotstable@colindex=\c@pgfplotstable@numcols\relax
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{##1\g@addto@macro\@tempa{ ##1\\\midrule\endhead}\\\midrule\endfirsthead\@tempa}%
                        \@tempa
        \else
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{##1\g@addto@macro\@tempa{ ##1&} & }%
        \fi
           \fi
    },
},
 every last row/.style={after row=\bottomrule}
]{testdata.dat}
\makeatother

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

\documentclass[a5paper]{article}
\usepackage{pgfplotstable} 
\usepackage{booktabs} 
\usepackage{filecontents}
\usepackage{longtable}

\begin{document}
\begin{filecontents}{testdata.dat}
Idx  Nam Dim Grd
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
1   Ady 53  F
2   Bar 72  C
3   Cor 83  B
4   Dar 58  D
5   Esa 68  C
6   Foo 67  C
7   Gar 74  C
8   Hur 65  D
9   Jaz 85  B
10  Ker 91  A
\end{filecontents}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},}
I am referencing to the long table~\ref{aLabel}.
\makeatletter
\pgfplotstabletypeset[col sep=space,header=true,    
columns={Idx,Nam,Dim,Grd},      % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},%
every head row/.append style={%
    typeset cell/.code={%
       \ifnum\c@pgfplotstable@colindex=1\relax
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{
                             \caption{A caption}\label{aLabel}\\\toprule ##1 \gdef\@tempa{\caption*{A caption}\\\toprule ##1&} &}%
       \else
        \ifnum\c@pgfplotstable@colindex=\c@pgfplotstable@numcols\relax
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{##1\g@addto@macro\@tempa{ ##1\\\midrule\endhead}\\\midrule\endfirsthead\@tempa}%
                        \@tempa
        \else
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{##1\g@addto@macro\@tempa{ ##1&} & }%
        \fi
           \fi
    },
},
 every last row/.style={after row=\bottomrule}
]{testdata.dat}

\end{document}

相关内容