我有几次相同的表(有 n 行),我想突出显示某些行。
但我需要在每种情况下跳过一些行(即“跳过行 0,...,x”或“跳过行 x,...,n”等)。
这意味着 pgfplotstable 正在改变数字。
我怎样才能坚持原来的编号,例如这里的第 3 行。
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{colortbl}
\pgfplotstableread[]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
}{\mytable}
\begin{document}
\section{The row with Number 3 should be highlighted in both Tables}
\subsection{Good}
\pgfplotstabletypeset[string type,
every row no 3/.style={ before row=\rowcolor{yellow}},
skip rows between index={5}{6}
]{\mytable}
\subsection{Bad}
\pgfplotstabletypeset[string type,
every row no 3/.style={ before row=\rowcolor{yellow}},
skip rows between index={0}{2}
]{\mytable}
\end{document}
答案1
看起来并不难pgfplotstable
与...合作tabularray
包。使用tabularray
它可以轻松更改表格的样式。
新解决方案
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{tabularray}
\pgfplotstableread[]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
}{\mytable}
\newcommand{\MyGobble}[1]{}
\begin{document}
\section{Highlight rows with number 3 with tabularray}
\subsection{Good}
\pgfplotstabletypeset[
string type,
skip coltypes,
begin table=\begin{tblr}{
stretch = 0,
rowsep = {3pt},
columns = {c},
row{5} = {yellow9},
row{7} = {rowsep=0pt,cmd=\MyGobble},
},
end table=\end{tblr},
]{\mytable}
\subsection{Also Good}
\pgfplotstabletypeset[
string type,
skip coltypes,
begin table=\begin{tblr}{
stretch = 0,
rowsep = {3pt},
columns = {c},
row{5} = {yellow9},
row{2-3} = {rowsep=0pt,cmd=\MyGobble},
},
end table=\end{tblr},
]{\mytable}
\end{document}
旧解决方案
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{tabularray}
\pgfplotstableread[]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
}{\mytable}
\newcommand{\MyGobble}[1]{}
\NewTblrEnviron{mytblra}
\SetTblrInner[mytblra]{
stretch = 0,
rowsep = {3pt},
row{5} = {yellow9},
row{7} = {rowsep=0pt,cmd=\MyGobble},
}
\NewTblrEnviron{mytblrb}
\SetTblrInner[mytblrb]{
stretch = 0,
rowsep = {3pt},
row{5} = {yellow9},
row{2-3} = {rowsep=0pt,cmd=\MyGobble},
}
\begin{document}
\section{Highlight rows with number 3 with tabularray}
\subsection{Good}
\pgfplotstabletypeset[
string type,
begin table=\begin{mytblra},
end table=\end{mytblra},
]{\mytable}
\subsection{Also Good}
\pgfplotstabletypeset[
string type,
begin table=\begin{mytblrb},
end table=\end{mytblrb},
]{\mytable}
\end{document}