2

I read this article on "How to change a whole row of a table" but my problem is that I have my table created with pgfplotstable from an external file.

How could I set bold the characters of row number 7?

This is in my preamble

% 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}
}

Then locally

% 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}

This is my table file

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,
2
  • Could you make a complete MWE including the data from the csv file, please.
    – Philipp
    Aug 23, 2013 at 0:00
  • I edited my answer. I found a more generic way to embolden a row which will be more convenient for more than one table.
    – Philipp
    Aug 23, 2013 at 15:07

1 Answer 1

2

Updated Answer

After searching quite some time I found this which helped me to find a more convenient solution for you problem by creating a row style that does the postprocessing work. This will come in handy if you want to use it on more than one table.

\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}

Original Answer

Unfortunately I couldn't figure out an automatic solution but you can get what you want by using every row <row> column <col>/.style={postproc cell content/.style={@cell content=\textbf{##1}}} for every column in your table. For empty cells I had to include a little if-clause via etoolbox's command \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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .