pgfplotstable: Ändern Sie die Farbe des Inhalts einer Zelle im Zeichenfolgentyp, während der Stil beibehalten wird

pgfplotstable: Ändern Sie die Farbe des Inhalts einer Zelle im Zeichenfolgentyp, während der Stil beibehalten wird

Erweiterung des Themas inpgfplotstable: Wie kann ich die Farbe des Zellinhalts ändern und gleichzeitig den Stil beibehalten?, richtig gelöst durch@frougon, ich muss die Farbe einer einzelnen Zelle in ändern string style, ich verwende zum siunitxRunden von Zahlen in .string styletype 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}

wenn ich den Stil einer Zelle ändere, hat die Rundung keinen Effekt mehr und ich erhalte:

Antwort1

Sie müssen lediglich verwenden 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}

Bildbeschreibung hier eingeben

NACHTRAG: Wenn Sie mit der Schriftstärke usw. experimentieren möchten, können Sie festlegen, siunitxdass Sie nicht ignoriert werden. Eine Möglichkeit hierfür besteht darin, die detect-all=trueOption hinzuzufügen \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}

Bildbeschreibung hier eingeben

Antwort2

Bitte beachten Sie, dass ich dieandere Antwort\pgfkeysgetvalue{/pgfplots/table/@cell content}{...}den Ansatz zu verwenden my special cell/.expanded={...}, anstatt Zellinhalte abzurufenohne es zu früh auszudehnen,bevor Sie es einwickeln \textcolor.

Es scheint möglich zu sein , siunitxmit zu verwenden pgfplotstable, 1 wird jedoch siunitxnicht im pgfplotstableHandbuch erwähnt. Daher werde ich vorerst nur den dort erwähnten Ansatz vorschlagen, nämlich die Verwendung von . Standardmäßig wird dabei eine horizontale Zentrierung innerhalb der Spalte verwendet, Sie können jedoch mit oder /pgfplots/table/dec sep aligneinen anderen Ausrichtungstyp angeben . Los geht‘s. :-)dec sep align=ldec 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}

Bildbeschreibung hier eingeben

Fußnote

  1. Sehen Sie sich dieAntwort von Schrödingers Katze!

verwandte Informationen