
Expandindo o tema abordado empgfplotstable: como posso alterar a cor do conteúdo de uma célula mantendo o estilo?, resolvido corretamente por@frougon, preciso mudar a cor de uma única célula em string style
, uso siunitx
para arredondar números em string style
using type column={S}
.
\documentclass{scrbook}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
round-mode = places,
round-precision = 2, % precisión
}
\begin{filecontents*}{my-data.csv}
c1 & c2 & c3
Story4 & 33.7835 & 33.7878
Story3 & 38.4334 & 38.4334
Story2 & 37.7156 & 37.7156
Story1 & 38.4056 & 38.4034
\end{filecontents*}
\pgfplotstableread[col sep=&]{my-data.csv}\myLoadedTable
\begin{document}
\begin{table}
\pgfplotstabletypeset[
display columns/0/.style={column type={c},
column name=\textbf{$Story$}, string type},
display columns/1/.style={column type={S},
column name=\textbf{$U_x$}, string type},
display columns/2/.style={column type={S},
column name=\textbf{$U_y$},string type},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\bottomrule}},
my special cell/.style={@cell content=\textcolor{blue}{#1}},
every row 3 column 2/.append style={
postproc cell content/.append style={
my special cell/.expanded={%
\pgfkeysvalueof{/pgfplots/table/@cell content}%
},
},
},]{\myLoadedTable}
\end{table}
\end{document}
ao alterar o estilo de uma célula, o arredondamento deixa de ter efeito, recebo:
Responder1
Tudo que você precisa é usar my special cell/.style={@cell content=\color{blue}#1}
.
\documentclass{scrbook}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
round-mode = places,
round-precision = 2, % precisión
}
\begin{filecontents*}{my-data.csv}
c1 & c2 & c3
Story4 & 33.7835 & 33.7878
Story3 & 38.4334 & 38.4334
Story2 & 37.7156 & 37.7156
Story1 & 38.4056 & 38.4034
\end{filecontents*}
\pgfplotstableread[col sep=&]{my-data.csv}\myLoadedTable
\begin{document}
\begin{table}
\pgfplotstabletypeset[
display columns/0/.style={column type={c},
column name=\textbf{$Story$}, string type},
display columns/1/.style={column type={S},
column name=\textbf{$U_x$}, string type},
display columns/2/.style={column type={S},
column name=\textbf{$U_y$},string type},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\bottomrule}},
my special cell/.style={@cell content=\color{blue}#1},
every row 3 column 2/.append style={
postproc cell content/.append style={
my special cell/.expanded={%
\pgfkeysvalueof{/pgfplots/table/@cell content}%
},
},
},]{\myLoadedTable}
\end{table}
\end{document}
TERMO ADITIVO: Se você quiser brincar com o peso da fonte e assim por diante, você pode instruir siunitx
para não ignorá-lo. Uma maneira de fazer isso é adicionar a detect-all=true
opção ao \sisetup
.
\documentclass{scrbook}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
round-mode = places,
round-precision = 2, % precisión
detect-all=true
}
\begin{filecontents*}{my-data.csv}
c1 & c2 & c3
Story4 & 33.7835 & 33.7878
Story3 & 38.4334 & 38.4334
Story2 & 37.7156 & 37.7156
Story1 & 38.4056 & 38.4034
\end{filecontents*}
\pgfplotstableread[col sep=&]{my-data.csv}\myLoadedTable
\begin{document}
\begin{table}
\pgfplotstabletypeset[
display columns/0/.style={column type={c},
column name=\textbf{$Story$}, string type},
display columns/1/.style={column type={S},
column name=\textbf{$U_x$}, string type},
display columns/2/.style={column type={S},
column name=\textbf{$U_y$},string type},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\bottomrule}},
my special cell/.style={@cell content=\color{blue}\bfseries#1},
every row 3 column 2/.append style={
postproc cell content/.append style={
my special cell/.expanded={%
\pgfkeysvalueof{/pgfplots/table/@cell content}%
},
},
},]{\myLoadedTable}
\end{table}
\end{document}
Responder2
Observe que atualizei ooutra respostausar a \pgfkeysgetvalue{/pgfplots/table/@cell content}{...}
abordagem em vez de my special cell/.expanded={...}
recuperar o conteúdo da célulasem expandi-lo para o início,antes de embrulhá-lo dentro \textcolor
.
Parece ser possível usar siunitx
com pgfplotstable
, 1 porém siunitx
não é mencionado no pgfplotstable
manual. Assim, por enquanto, proporei apenas a abordagem mencionada lá, que é usar /pgfplots/table/dec sep align
. Por padrão, isso usa centralização horizontal dentro da coluna, mas você pode definir um tipo de alinhamento diferente com dec sep align=l
ou dec sep align=r
. Aqui vamos nós. :-)
\documentclass{article}
\usepackage{xcolor}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\usepackage{booktabs}
\begin{filecontents*}{my-data.csv}
c1 & c2 & c3
Story4 & 33.7835 & 33.7878
Story3 & 38.4334 & 38.4334
Story2 & 37.7156 & 37.7156
Story1 & 38.4056 & 38.4034
\end{filecontents*}
\pgfplotstableread[col sep=&]{my-data.csv}\myLoadedTable
\begin{document}
\pgfplotstabletypeset[
my numeric col/.style={fixed, fixed zerofill, precision=2, dec sep align},
columns/c1/.style={column type={c}, column name=\textbf{Story}, string type},
columns/c2/.style={my numeric col, column name=$U_x$},
columns/c3/.style={my numeric col, column name=$U_y$},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\bottomrule}},
my special cell/.style={@cell content=\textcolor{blue}{#1}},
every row 3 column 2/.append style={
postproc cell content/.append code={%
\pgfkeysgetvalue{/pgfplots/table/@cell content}{\myTmpCellContents}%
\pgfkeysalso{my special cell/.expand once={\myTmpCellContents}}%
},
}]{\myLoadedTable}
\end{document}
Nota de rodapé