TeX - LaTeX Asked on April 27, 2021
I want to color a row (column) from a cell with special content, e.g. ‘x’.
I tried to use
every nth row={rememberrow}{before row=rowcolor{orange}}, % WORKS NOT!
in the solution.
xdefremembercol{pgfplotstablecol}%
xdefrememberrow{pgfplotstablerow}%
expands correctly after the pgfplotstabletypeset
, but not while the typeset.
What do I have to do?
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
defliteralx{x}
begin{document}
pgfplotstabletypeset[
postproc cell content/.code={%
deftemp{#1}%
ifxtempliteralx
xdefremembercol{pgfplotstablecol}%
xdefrememberrow{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}
With savebox and newcommand it works:
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}
defliteralx{x}
begin{document}
pgfplotstableset{ myhighlights/.style={} }
newcommandMyTable{%
pgfplotstabletypeset[myhighlights,
postproc cell content/.code={%
deftemp{##1}% <--- ! '##', not '#'
ifxtempliteralx
xdefremembercol{pgfplotstablecol}%
xdefrememberrow{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 rememberrowspace column no remembercol/.style={
@cell content/.add={cellcolor{CellColor}}{}, },% <--- ! 'space'
}%% =======
}
MyTable
end{document}
Correct answer by cis on April 27, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP