pgfplotstable : 스타일에 대해 read out row- (column-) 값을 사용하는 방법
특수한 내용 (예 : 'x')이있는 셀의 행 (열)에 색을 지정하고 싶습니다.
솔루션
every nth row={\rememberrow}{before row=\rowcolor{orange}}, % WORKS NOT!
에서 사용하려고했습니다 .
\xdef\remembercol{\pgfplotstablecol}%
\xdef\rememberrow{\pgfplotstablerow}%
다음에 올바르게 확장 pgfplotstabletypeset
되지만 조판 중에는 확장 되지 않습니다.
나는 무엇을해야합니까?
\documentclass[]{article}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableset{string type, col sep=comma, header=false}
\pgfplotstableread[]{
a, b, c
d, e, f
g, x, i
j, k, l
}\mytable
\def\literalx{x}
\begin{document}
\pgfplotstabletypeset[
postproc cell content/.code={%
\def\temp{#1}%
\ifx\temp\literalx
\xdef\remembercol{\pgfplotstablecol}%
\xdef\rememberrow{\pgfplotstablerow}%
\fi
},
%every nth row={\rememberrow}{before row=\rowcolor{orange}}, % WORKS NOT!
]{\mytable}
\textbf{Works:} x is in row no.~\rememberrow\ and column no.~\remembercol.
\end{document}
답변
cis
savebox 및 newcommand를 사용하면 다음과 같이 작동합니다.
\documentclass[]{article}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableset{string type, col sep=comma, header=false}
\pgfplotstableread[]{
a, b, c
d, e, f
g, x, i
j, k, l
}\mytable
\colorlet{CellColor}{red}
\colorlet{RowColor}{orange}
\colorlet{ColColor}{pink}
\def\literalx{x}
\begin{document}
\pgfplotstableset{ myhighlights/.style={} }
\newcommand\MyTable{%
\pgfplotstabletypeset[myhighlights,
postproc cell content/.code={%
\def\temp{##1}% <--- ! '##', not '#'
\ifx\temp\literalx
\xdef\remembercol{\pgfplotstablecol}%
\xdef\rememberrow{\pgfplotstablerow}%
\fi
},
]{\mytable}%
}
\newsavebox{\Mybox}
\savebox{\Mybox}{\MyTable}
\section{Raw Table}
\usebox{\Mybox}
\section{Read out row and column -- works}
x is in row no.~\rememberrow\ and column no.~\remembercol.
\section{Typeset highlighted Table -- works as well}
\pgfplotstableset{myhighlights/.style={%% =======
% Highlight Row:
every row no \rememberrow/.style={
before row={\rowcolor{RowColor}} },
% Highlight Column:
every col no \remembercol/.style={
column type/.add={>{\columncolor{ColColor}}}{} },
% Highlight Cell
every row no \rememberrow\space column no \remembercol/.style={
@cell content/.add={\cellcolor{CellColor}}{}, },% <--- ! '\space'
}%% =======
}
\MyTable
\end{document}