2

I wished to bold some numbers in a table I am showing with pgfplotstable. The manual and this answer

suggest using

every row 2 column 1/.style={ %Row number just for example
    postproc cell content/.style={
      @cell content/.add={$\bf}{$}
    }
  },

However, when I do that it puts the numbers out of alignment because the bolded ones are too wide.

Screenshot showing  miss-alignment

After reading a bit about typography, I've concluded that what I want is to display the numbers using a font featuring tabular figures, with duplexing so that bold has the same widths.

I looked at this answer for normal tabular tables, and it shows exactly what I want. However when I tried:

every row 4 column 1/.style={ %Row number just for example
    postproc cell content/.style={
      @cell content/.add={\fontseries{b}\selectfont}{}
    }
  },

There was no change. It didn't even make it bold at all.

Minimal verifiable example:

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}
\pgfplotstabletypeset[
    precision=5, fixed zerofill=true,
    every row 2 column 1/.style={
        postproc cell content/.append style={
            @cell content/.add={$\bf}{$}
        }
    }
]{
a b
5 1.23
6 1.6311
7 4.231
9 2.10144
}
\end{document}

1 Answer 1

3

Problem you are running into, and why the \fontseries command isn't working for you, is that pgfplotstables formats all numbers in math mode -- like if they were between $ signs. \fontseries does not effect the fonts used in math mode. What you can do instead to change the font used in math mode (for that cell) follows. It is based on the answer to a similar question about making pgfplotstables uses \sffamily

One can declare a version of the normal font that is bold (b) not bold-extended (bx)

using

\DeclareMathVersion{tabularbold}
\SetSymbolFont{operators}{tabularbold}{OT1}{cmr}{b}{n}

in the preamble.

Then you can switch to it for a section using \mathversion{tabularbold}, as in

every row 2 column 1/.style={
    postproc cell content/.append style={
        @cell content/.add={\mathversion{tabularbold}}{}
   }
}

screenshot showing alignment is correct

Full example:

\documentclass{article}
\usepackage{pgfplotstable}

\DeclareMathVersion{tabularbold}
\SetSymbolFont{operators}{tabularbold}{OT1}{cmr}{b}{n}
\begin{document}
\pgfplotstabletypeset[
precision=5, fixed zerofill=true,
every row 2 column 1/.style={
    postproc cell content/.append style={
        @cell content/.add={\mathversion{tabularbold}}{}
    }
}
]{
a b
5 1.23
6 1.6311
7 4.231
9 2.10144
}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.