我读这关于“如何更改表格的整行”的文章,但我的问题是,我使用外部文件中的 pgfplotstable 创建了表格。
我该如何设置大胆的第 7 行的字符?
这是我的序言
% For tables
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{caption}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.5em}}
\newcolumntype{D}{>{\arraybackslash}m{15em}}
\newcolumntype{E}{>{\centering\arraybackslash}m{3.4em}}
\newcolumntype{F}{>{\centering\arraybackslash}m{4.4em}}
\pgfplotstableset{
font={\small},
empty cells with={--}, % replace empty cells with ’--’
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
}
然后在本地
% Add table
\begin{table} [h]
\caption{Breakdown of participation by gender (dependent variable) (percentage)}
\centering
\pgfplotstabletypeset[
columns/Form of participation/.style={string type, column type=D},
col sep=comma] {/my/path/power_distortions_off_online/gender_dependent.csv}
\captionsetup{font={footnotesize,bf,it}}
\caption*{Source: p. 196}
\label{gender_dependent}
\end{table}
这是我的表格文件
Form of participation,No answer,Male,Female,Total
No reply,8.3,58.3,33.3,100
I attended one or more public meetings,3.7,63.9,32.4,
I attended other meetings about the public meetings,10.3,69,20.7,
I posted to the CPDP blog,11.1,66.7,22.2,
I asked a question on the DPOP Web site,7.7,84.6,7.7,
I asked a question by letter or prepaid postcard,22.2,55.6,22.2,
I asked a question or commented at a public meeting,10,83.9,16.1,
I looked for more information by mail or in documents,12.2,69.4,18.4,
I visited the CPDP Web sire,6.5,71.4,22.1,
Other,14.3,71.4,14.3,
Total,7.4,62.6,30.1,
答案1
更新答案
经过一段时间的搜索我发现这通过创建可执行后处理工作的行样式,我找到了更方便的解决方案。如果您想在多个表上使用它,这将非常有用。
\documentclass{article}
% For tables
\usepackage{pgfplotstable}
\usepackage{etoolbox} % this is needed to get \ifstrempty
\usepackage{booktabs}
\usepackage{array}
\usepackage{caption}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.5em}}
\newcolumntype{D}{>{\arraybackslash}m{15em}}
\newcolumntype{E}{>{\centering\arraybackslash}m{3.4em}}
\newcolumntype{F}{>{\centering\arraybackslash}m{4.4em}}
\pgfplotstableset{
font={\small},
empty cells with={--},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
row style/.style={
every row #1 column 0/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 1/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 2/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 3/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 4/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 5/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 6/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 7/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 8/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 9/.style= {postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 10/.style={postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}},
every row #1 column 11/.style={postproc cell content/.style={@cell content=\textbf{\ifstrempty{####1}{--}{####1}}}}
}
}
\begin{filecontents}{gender_dependent.csv}
Form of participation,No answer,Male,Female,Total
No reply,8.3,58.3,33.3,100
I attended one or more public meetings,3.7,63.9,32.4,
I attended other meetings about the public meetings,10.3,69,20.7,
I posted to the CPDP blog,11.1,66.7,22.2,
I asked a question on the DPOP Web site,7.7,84.6,7.7,
I asked a question by letter or prepaid postcard,22.2,55.6,22.2,
I asked a question or commented at a public meeting,10,83.9,16.1,
I looked for more information by mail or in documents,12.2,69.4,18.4,
I visited the CPDP Web sire,6.5,71.4,22.1,
Other,14.3,71.4,14.3,
Total,7.4,62.6,30.1,
\end{filecontents}
\pgfplotstableread[col sep=comma]{gender_dependent.csv}{\gender}
\begin{document}
% Add table
\begin{table} [h]
\caption{Breakdown of participation by gender (dependent variable) (percentage)}
\centering
\pgfplotstabletypeset[
columns/Form of participation/.style={string type, column type=D},
row style={7}
] {\gender}
\captionsetup{font={footnotesize,bf,it}}
\caption*{Source: p. 196}
\label{gender_dependent}
\end{table}
\end{document}
原始答案
不幸的是,我无法找到自动解决方案,但您可以通过every row <row> column <col>/.style={postproc cell content/.style={@cell content=\textbf{##1}}}
对表格中的每一列使用来获得所需的结果。对于空单元格,我必须通过etoolbox
命令包含一个小的 if 子句\ifstrempty
。
\documentclass{article}
% For tables
\usepackage{pgfplotstable}
\usepackage{etoolbox} % this is needed to get \ifstrempty
\usepackage{booktabs}
\usepackage{array}
\usepackage{caption}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.5em}}
\newcolumntype{D}{>{\arraybackslash}m{15em}}
\newcolumntype{E}{>{\centering\arraybackslash}m{3.4em}}
\newcolumntype{F}{>{\centering\arraybackslash}m{4.4em}}
\pgfplotstableset{
font={\small},
empty cells with={--},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
}
\begin{filecontents}{gender_dependent.csv}
Form of participation,No answer,Male,Female,Total
No reply,8.3,58.3,33.3,100
I attended one or more public meetings,3.7,63.9,32.4,
I attended other meetings about the public meetings,10.3,69,20.7,
I posted to the CPDP blog,11.1,66.7,22.2,
I asked a question on the DPOP Web site,7.7,84.6,7.7,
I asked a question by letter or prepaid postcard,22.2,55.6,22.2,
I asked a question or commented at a public meeting,10,83.9,16.1,
I looked for more information by mail or in documents,12.2,69.4,18.4,
I visited the CPDP Web sire,6.5,71.4,22.1,
Other,14.3,71.4,14.3,
Total,7.4,62.6,30.1,
\end{filecontents}
\pgfplotstableread[col sep=comma]{gender_dependent.csv}{\gender}
\begin{document}
% Add table
\begin{table} [h]
\caption{Breakdown of participation by gender (dependent variable) (percentage)}
\centering
\pgfplotstabletypeset[
columns/Form of participation/.style={string type, column type=D},
every row 7 column 0/.style={postproc cell content/.style={@cell content=\textbf{##1}}},
every row 7 column 1/.style={postproc cell content/.style={@cell content=\textbf{##1}}},
every row 7 column 2/.style={postproc cell content/.style={@cell content=\textbf{##1}}},
every row 7 column 3/.style={postproc cell content/.style={@cell content=\textbf{##1}}},
every row 7 column 4/.style={postproc cell content/.style={@cell content=\textbf{\ifstrempty{##1}{--}{##1}}}}
] {\gender}
\captionsetup{font={footnotesize,bf,it}}
\caption*{Source: p. 196}
\label{gender_dependent}
\end{table}
\end{document}