1

I've defined a command like so:

\makeatletter
\newcommand{\ion}[2]{#1$\;$\textsc{\rmfamily\@roman{#2}}\relax}
\makeatother

The purpose is to typeset an ionization state with small caps roman numerals (e.g., \ion{He}{2}). This works fine in the main body of my text, and in table footnotes, but in the header columns it fails. Here's an example:

enter image description here

Any suggestions for how to fix this?

  • 2
    unrelated to the table, Most font families do not have bold caps and small caps, so you need to give up the bold or change fonts. (LaTeX would have warned about this in the log) – David Carlisle May 22 '15 at 15:48
3

Minimized MWE, because this is not related to a table header, but to the bold font used there:

\documentclass{article}

\makeatletter
\newcommand{\ion}[2]{#1$\;$\textsc{\rmfamily\@roman{#2}}\relax}
\makeatother

\begin{document}
  \ion{He}{4}
  \textbf{\ion{He}{4}}
\end{document}

You get the wrong appearance:

Result with wrong font

and a warning:

LaTeX Font Warning: Font shape `OT1/cmr/bx/sc' undefined
(Font)              using `OT1/cmr/bx/n' instead on input line 9.

That means, a bold version with small caps is not available and the regular (normal) bold font is used. The Computer Modern fonts as its successors the Latin Modern fonts miss a bold variant for small caps. A font with a bold variant is TG Termes a Times Roman clone from TeX Gyre font project:

\usepackage{tgtermes}

Result TG Termes

A poor man's solution would be to fake the small caps for the bold font by using uppercase letters and scaling them down to the size of the small caps lowercase letters. At least this avoids changing the entire font family.

\documentclass{article}
\usepackage{graphicx}

\makeatletter
\newcommand{\ion}[2]{%
  #1$\;$%
  % Test for bold font by inspecting \f@series, it can be "b" or "bx"
  \if b\expandafter\@car\f@series\relax\@nil
    \begingroup % keep changes to scratch box register 0 local
      \sbox0{\rmfamily\mdseries\textsc{v}}%
      \resizebox{!}{\ht0}{\rmfamily\@Roman{#2}}%
    \endgroup
  \else
    \textsc{\rmfamily\@roman{#2}}%
  \fi
}
\makeatother

\begin{document}
  \ion{He}{4}
  \textbf{\ion{He}{4}}
\end{document}

Result faked small caps

And now a robust version with hyperref support. Then \ion can also be used inside captions and section titles:

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{bookmark}

\makeatletter
\newcommand{\ion}{}% Check, that \ion is not yet defined
\DeclareRobustCommand*{\ion}[2]{%
  #1$\;$%
  % Test for bold font by inspecting \f@series, it can be "b" or "bx"
  \if b\expandafter\@car\f@series\relax\@nil
    \begingroup % keep changes to scratch box register 0 local
      \sbox0{\rmfamily\mdseries\textsc{v}}%
      \resizebox{!}{\ht0}{\rmfamily\@Roman{#2}}%
    \endgroup
  \else
    \textsc{\rmfamily\@roman{#2}}%
  \fi
}
\makeatother

% hyperref support
\pdfstringdefDisableCommands{%
  \renewcommand*{\ion}[2]{%
    #1 %
    \@Roman{#2}% LaTeX's version via \@slowromancap is expandable
  }%
}

\begin{document}
  \tableofcontents
  \section{\ion{He}{4}}
  \ion{He}{4}
  \textbf{\ion{He}{4}}
\end{document}

Result robust/hyperref

| improve this answer | |
  • Maybe making \ion a robust command? – egreg May 22 '15 at 16:19
  • @egreg Done. Also support for hyperref is added. – Heiko Oberdiek May 22 '15 at 16:33
1

If you don't want to use a different font, consider simply loading bold-extra. This is similar to the "poor man's solution" mentioned in Heiko's reply, except that it actually builds a real, true-blue bold small cap font from the Computer Modern sources, without scaling and the concomitant loss of quality.

\documentclass{article}
\usepackage{bold-extra}
\begin{document}
\textsc{He iv}---\textbf{He iv}---\textsc{\textbf{He iv}}
\end{document}

Note that these are Metafont sources, which to my knowledge have never been converted to an outline format; this means you'll have bitmaps in your pdf. But that's not so bad in modern pdf viewers; the screenshot below is from xpdf:

Bold small caps example from bold-extra.

The other benefit here is that you have fonts that exactly match the rest of your body fonts (assuming you're using Computer/Latin Modern).

| improve this answer | |

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.