
행을 강조하고 싶습니다. n*(n+3)/2 = 0, 2, 5, 9, 14, 20, 27, 35,...
용어를 사용하여 최선의 방법을 자동화하려면 어떻게 해야 합니까 n*(n+3)/2
?
\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\begin{document}
\pgfplotstableset{
highlightrow/.style={
postproc cell content/.append code={
\count0=\pgfplotstablerow
\advance\count0 by0
\ifnum\count0=#1
% \pgfkeysalso{@cell content/.add={$\bf}{$}}
\pgfkeysalso{@cell content=\textbf{##1}}%
\fi}, }, }
%\def\List{7,9,10}
\pgfplotstabletypeset[string type,
highlightrow=0, % works
highlightrow/.list={2,5,9}, % works
%highlightrow/.list=\List, % works not
]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
6 x x
7 x x
8 x x
9 x x
10 x x
11 x x
}
\end{document}
답변1
handlers/.list
\foreach
목록을 펼치는 데 사용됩니다 .
\foreach \pgf@keys@key in{#1}%
pgffor
선행이 있는지 확인하여 다양한 방식으로 목록을 처리 합니다 \bgroup
.
\def\pgffor@@vars@end in{%
\pgfutil@ifnextchar\bgroup{\pgffor@normal@list}{\pgffor@macro@list}%
}
매크로 목록(지지되지 않은)는 일반 목록(보강된) 첫 번째:
\def\pgffor@macro@list#1{%
\expandafter\pgffor@normal@list\expandafter{#1}}
그래서 당신이 작성 highlightrow=\List
하고 그것이 다음과 같이 처리되기를 기대하면매크로 목록, 그러나 실제로 \List
는보강된다음과 같이 처리됩니다.일반 목록그러면 오류가 발생합니다.
문제를 해결하는 가장 빠른 방법은 무엇입니까?울리케 피셔그녀의 의견에서 다음과 같이 언급했습니다 highlightrow/.list/.expand once=\List
.
나는기능로 행 인덱스를 얻으려면 expl3
.
\documentclass[margin=1cm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\usepackage{xparse}
\pgfplotstableset{
highlightrow/.style 2 args={
postproc cell content/.append code={
\ifnum\pgfplotstablerow=#1
\pgfkeysalso{@cell content={#2##1}}%
\fi
},
},
}
\ExplSyntaxOn
\NewDocumentCommand { \rowstyle } { O{30} O{#1} m }
{
\row_style:nnn { #1 } { #2 } { #3 }
}
\int_new:N \l__i_int
\int_new:N \l__index_int
\cs_new_protected:Nn \row_style:nnn
{
\cs_set:Nn \__parse_expr:n
{
\fp_to_int:n { floor(#2) }
}
\fp_compare:nT { #1 >= 0 }
{
\int_zero:N \l__i_int
\fp_while_do:nn { \__parse_expr:n { \l__i_int } <= #1 }
{
\tl_set:Nx \l_tempa_tl {
\exp_not:N \pgfplotstableset{
highlightrow={\__parse_expr:n { \l__i_int }}{ \exp_not:n { #3 } }
}
}
\tl_use:N \l_tempa_tl
\int_incr:N \l__i_int
}
}
}
\ExplSyntaxOff
\begin{document}
\rowstyle[11][#1*(#1 + 3)/2]{\color{red}}
\rowstyle[11][(#1 + 1)*4]{\color{blue}\bfseries}
\pgfplotstabletypeset[string type]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
6 x x
7 x x
8 x x
9 x x
10 x x
11 x x
}
\end{document}
답변2
팁으로 highlightrow/.list/.expand once=\List
나는 pgfmath-solution을 사용합니다.
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\pgfplotstableread[]{
A B C
0 x x
1 x x
2 x x
3 x x
4 x x
5 x x
6 x x
7 x x
8 x x
9 x x
10 x x
11 x x
}{\mytable}
\begin{document}
\pgfplotstablegetrowsof{\mytable}
\pgfmathsetmacro\Rows{int(\pgfplotsretval-1)}
Rows: \Rows.
% Solution of Rows = n*(n+3)/2
\pgfmathsetmacro\N{int(floor(0.5*(sqrt(8*\Rows+9)-3)))}
Maximal n: \N=N
% List:
\let\List=\empty% create List
\foreach \n in {0,...,\N}
{%
\pgfmathparse{int(\n*(\n+3)/2}%
\ifx\empty\List{} \xdef\List{\pgfmathresult}%
\else \xdef\List{\List,\pgfmathresult}%
\fi
}
List: \List
\pgfplotstableset{
highlightrow/.style={
postproc cell content/.append code={
\count0=\pgfplotstablerow
\advance\count0 by0
\ifnum\count0=#1
% \pgfkeysalso{@cell content/.add={$\bf}{$}}
\pgfkeysalso{@cell content=\color{red}\textbf{##1}}%
\fi}, },
}
\pgfplotstabletypeset[string type,
%highlightrow=0,%
highlightrow/.list/.expand once=\List,
]{\mytable}
\end{document}a