
で取り上げたトピックを拡張するpgfplotstable: スタイルを維持しながらセルの内容の色を変更するにはどうすればよいですか?、正しく解決されましたふるーごん、 の 1 つのセルの色を変更する必要がありますstring style
。を使用してsiunitx
の数値を四捨五入します。string style
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}
セルのスタイルを変更すると、丸めが効かなくなり、次のようになります。
答え1
必要なのは を使用することだけです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}
付録: フォントの太さなどをいじりたい場合は、siunitx
無視しないように指示したほうが良いかもしれません。そのための 1 つの方法は、detect-all=true
にオプションを追加することです\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}
答え2
更新しましたので、その他の回答セルの内容を取得するためにで\pgfkeysgetvalue{/pgfplots/table/@cell content}{...}
はなく、アプローチを使用するmy special cell/.expanded={...}
早期に拡大することなく、中に包む前に\textcolor
。
を1siunitx
で使用することは可能のようですが、マニュアルには記載されていません。そのため、今のところは、 を使用するという、マニュアルに記載されているアプローチのみを提案します。デフォルトでは、列内で水平方向の中央揃えが使用されますが、またはを使用して別の配置タイプを指定することもできます。それでは始めましょう。 :-)pgfplotstable
siunitx
pgfplotstable
/pgfplots/table/dec sep align
dec sep align=l
dec sep align=r
\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}
脚注
- を参照してくださいシュレーディンガーの猫の答え!