4

The question is similar to this: Decimals in table don't align with dcolumn when bolded

I want certain numbers in a table with dcolumn to be italic and to align with the others. I tried something similar to what was proposed for bold numbers:

\newcolumntype{I}[3]{>{\textit\DC@{#1}{#2}{#3}}c<{\DC@end}}

However, it doesn't work.

Example:

\documentclass[12pt]{article}
\usepackage{dcolumn}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{document}
    \begin{tabular}{..}
        \hline 
        1.5 & 0.19 \\ 
        \multicolumn{1}{B{.}{.}{-1}}{2.75} & 4.2 \\ 
        3.4 & \textit{8.0} \\ 
        \hline 
    \end{tabular} 
\end{document}

enter image description here

3 Answers 3

3

It's probably easiest just to specify the font twice

enter image description here

\documentclass[12pt]{article}
\usepackage{dcolumn}
\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{document}
    \begin{tabular}{..}
        \hline 
        1.5 & 0.19 \\ 
        \multicolumn{1}{B{.}{.}{-1}}{2.75} & 4.2 \\ 
        3.4 & \mathit{8}.\mathit{0} \\ 
        \hline 
    \end{tabular} 
\end{document}
3

You might define a new math version for getting digits in italic, but I'll first present a solution based on siunitx (parts are from https://tex.stackexchange.com/a/334323/4427)

\documentclass[12pt]{article}
\usepackage{siunitx,booktabs,etoolbox}

\begin{document}

\begin{table}
\centering

%% local redefinitions
\renewrobustcmd{\bfseries}{\fontseries{b}\selectfont}
\renewrobustcmd{\boldmath}{}

\begin{tabular}{
  S[table-format=1.2,detect-weight,mode=text]
  S[table-format=1.2,detect-weight,mode=text]
}
\toprule
          1.5  &          0.19 \\
\bfseries 2.75 &          4.2  \\
          3.4  & \itshape 8.0  \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

Alternative, with dcolumn:

\documentclass[12pt]{article}
\usepackage{dcolumn}

\DeclareMathVersion{italic}
\SetSymbolFont{operators}{italic}{OT1}{\familydefault}{m}{it}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{I}[3]{>{\mathversion{italic}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{document}
    \begin{tabular}{..}
        \hline
        1.5 & 0.19 \\
        \multicolumn{1}{B{.}{.}{-1}}{2.75} & 4.2 \\
        3.4 & \multicolumn{1}{I{.}{.}{-1}}{8.0} \\
        \hline
    \end{tabular}
\end{document}

enter image description here

2

Same idea as David's, but wrapped into a macro for convenience:

\documentclass[12pt]{article}
\usepackage{dcolumn}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother

% call \mathit separately for integer and decimal parts
\newcommand{\itnum}[2]{\mathit{#1}.{\mathit{#2}}}

\begin{document}
    \begin{tabular}{..}
        \hline 
        1.5 & 0.19 \\ 
        \multicolumn{1}{B{.}{.}{-1}}{2.75} & 4.2 \\ 
        3.4 & \itnum{8}{0} \\ 
        \hline 
    \end{tabular} 

You must log in to answer this question.

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