pgfplotstable: 스타일을 유지하면서 문자열 유형의 셀 내용 색상을 변경합니다.

pgfplotstable: 스타일을 유지하면서 문자열 유형의 셀 내용 색상을 변경합니다.

에서 다루는 주제 확장pgfplotstable: 스타일을 유지하면서 셀 내용의 색상을 어떻게 변경할 수 있나요?, 올바르게 해결됨@frougon, 에서 단일 셀의 색상을 변경해야 합니다 . 를 사용하여 숫자를 반올림하는 데 string style사용합니다 .siunitxstring 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}

셀 스타일을 변경하면 반올림이 더 이상 적용되지 않습니다.

답변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무시하지 말라고 지시하고 싶을 수도 있습니다. 이를 수행하는 한 가지 방법은 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함께 사용하는 것이 가능한 것으로 보이지만 설명서 에는 언급되어 있지 않습니다 . 따라서 지금은 거기에 언급된 접근 방식인 . 기본적으로 이는 열 내부의 수평 중심을 사용하지만 또는 를 사용하여 다른 정렬 유형을 지정할 수 있습니다 . 여기 있습니다. :-)pgfplotstablesiunitxpgfplotstable/pgfplots/table/dec sep aligndec 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}

여기에 이미지 설명을 입력하세요

각주

  1. 참조슈뢰딩거의 고양이의 대답!

관련 정보