![pgfplotstable 标题行内的粗体字体](https://linux22.com/image/397556/pgfplotstable%20%E6%A0%87%E9%A2%98%E8%A1%8C%E5%86%85%E7%9A%84%E7%B2%97%E4%BD%93%E5%AD%97%E4%BD%93.png)
我喜欢在 pgfplotstable 标题行中有一个定义,将标题文本变为粗体字体。类似于:
every head row/.style={before row={\toprule}, after row=\midrule, \textbf{#1}}
不幸的是所有尝试都失败了。
\documentclass[varwidth=true, border=1mm, 11pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}
\WarningFilter{latex}{File}
\begin{filecontents*}{load.csv}
Nr.:;One;Two;Three;Four;Five;Six
1;0,293;0,143;0,443;2,20;1,760;2,640
2;1,172;1,022;1,322;1,80;1,440;2,160
3;2,051;1,901;2,201;1,40;1,120;1,680
4;2,949;2,799;3,099;1,10;0,880;1,320
5;3,809;3,659;3,959;0,70;0,560;0,840
6;4,707;4,557;4,857;0,36;0,288;0,432
\end{filecontents*}
\usepackage{booktabs}
\begin{document}
\begin{table}[H]
\centering
\pgfplotstabletypeset[
col sep = semicolon,
precision = 3,
fixed zerofill,
/pgf/number format/read comma as period,
every head row/.style={before row={\toprule}, after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type},
% display columns/0/.style={string type, column name={\bf Nr.:}},
% display columns/1/.style={column name={\bf One}},
% display columns/2/.style={column name={\bf Two}},
% display columns/3/.style={column name={\bf Three}},
% display columns/4/.style={column name={\bf Four}},
% display columns/5/.style={column name={\bf Five}},
% display columns/6/.style={column name={\bf Six}}
]{load.csv}
\end{table}
\end{document}
与上面代码中的注释部分不同,我希望它是一个适用于整个头行的定义。这很重要,因为我喜欢阅读 CSV 文件。
答案1
摘自 Pgfplotstable 部分的文档
/pgfplots/table/assign column name/.code={〈...〉}
只需添加
assign column name/.style={/pgfplots/table/column name={\textbf{#1}}}
到你的\pgfplotstabletypeset
。
将该行添加到您的 MWE 对我来说是有用的。
\documentclass[varwidth=true, border=1mm, 11pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}
\WarningFilter{latex}{File}
\begin{filecontents*}{load.csv}
Nr.:;One;Two;Three;Four;Five;Six
1;0,293;0,143;0,443;2,20;1,760;2,640
2;1,172;1,022;1,322;1,80;1,440;2,160
3;2,051;1,901;2,201;1,40;1,120;1,680
4;2,949;2,799;3,099;1,10;0,880;1,320
5;3,809;3,659;3,959;0,70;0,560;0,840
6;4,707;4,557;4,857;0,36;0,288;0,432
\end{filecontents*}
\usepackage{booktabs}
\begin{document}
\begin{table}[H]
\centering
\pgfplotstabletypeset[
col sep = semicolon,
precision = 3,
fixed zerofill,
/pgf/number format/read comma as period,
every head row/.style={before row={\toprule}, after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type},
assign column name/.style={/pgfplots/table/column name={\textbf{#1}}}
% display columns/0/.style={string type, column name={\bf Nr.:}},
% display columns/1/.style={column name={\bf One}},
% display columns/2/.style={column name={\bf Two}},
% display columns/3/.style={column name={\bf Three}},
% display columns/4/.style={column name={\bf Four}},
% display columns/5/.style={column name={\bf Five}},
% display columns/6/.style={column name={\bf Six}}
]{load.csv}
\end{table}
\end{document}
答案2
这很大程度上受到了percusse 的回答,从中我了解到,执行时typeset cell
列和行是已知的,因此可以使用简单的\ifnum
s 根据列和/或行来执行操作。
\documentclass[varwidth=true, border=1mm, 11pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}
\WarningFilter{latex}{File}
\begin{filecontents*}{load.csv}
Nr.:;One;Two;Three;Four;Five;Six
1;0,293;0,143;0,443;2,20;1,760;2,640
2;1,172;1,022;1,322;1,80;1,440;2,160
3;2,051;1,901;2,201;1,40;1,120;1,680
4;2,949;2,799;3,099;1,10;0,880;1,320
5;3,809;3,659;3,959;0,70;0,560;0,840
6;4,707;4,557;4,857;0,36;0,288;0,432
\end{filecontents*}
\usepackage{booktabs}
\begin{document}
\begin{table}[H]
\centering
\pgfplotstabletypeset[
col sep = semicolon,
precision = 3,
fixed zerofill,
/pgf/number format/read comma as period,
every head row/.style={before row={\toprule}, after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type},
typeset cell/.append code={
\ifnum\pgfplotstablerow<0
\bfseries
\fi}
% display columns/0/.style={string type, column name={\bf Nr.:}},
% display columns/1/.style={column name={\bf One}},
% display columns/2/.style={column name={\bf Two}},
% display columns/3/.style={column name={\bf Three}},
% display columns/4/.style={column name={\bf Four}},
% display columns/5/.style={column name={\bf Five}},
% display columns/6/.style={column name={\bf Six}}
]{load.csv}
\end{table}
\end{document}