0

I am trying to produce a table with positive and negative values one above the other in same row. The problem I am having is that the alignment is gone when using newtxtext and newtxmath packages as fonts together with TeXLive 2022 (it works fine with <=2021 version). The negative numbers are shifted with respect to the positive ones, see:

Shifted positive/negative values

Without newtxtext and newtxmath packages, I get the desired alignment (it is still not perfect, but good enough):

Column aligned by latexit or overleaf

MWE:

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx, booktabs}
% \usepackage{newtxtext, newtxmath}

\begin{document}
\renewcommand{\arraystretch}{1.2}
\sisetup{round-mode=places, round-precision=3, retain-explicit-plus}
\begin{tabular}{c S S @{\,}S @{\,}S}
  \toprule

  \multicolumn{1}{c}{One} & \multicolumn{1}{c}{Two} & \multicolumn{1}{c}{Three} & \multicolumn{1}{c}{$\pm 1\sigma$} & \multicolumn{1}{c}{$\pm 2\sigma$} \\

  \midrule

  1400  & 0.2469 & 0.2494 & \(^{\num{+0.1462}}_{\num{-0.2217}}\) & \(^{\num{+0.7946}}_{\num{-0.7372}}\) \\
  2200  & 0.1433 & 0.1449 & \(^{\num{+0.3306}}_{\num{-0.2372}}\) & \(^{\num{+0.5893}}_{\num{-0.6317}}\) \\
  3400  & 0.3360 & 0.3396 & \(^{\num{+0.2250}}_{\num{-0.5221}}\) & \(^{\num{+0.8784}}_{\num{-0.8279}}\) \\

  \bottomrule
\end{tabular}
\end{document}

Desired output would be sth. like this:

desired outlook

7
  • The editor you're using is irrelevant, since the only thing it does is calling latex. So you should specify which version of LaTeX (or the TeX distribution) you're using.
    – Miyase
    Oct 19, 2022 at 8:40
  • I am using TeX Live 2022 with updated packages: pdflatex --version pdfTeX 3.141592653-2.6-1.40.24 (TeX Live 2022) kpathsea version 6.3.4 latexml --version Latexmk, John Collins, 17 Mar. 2022. Version 4.77
    – gasar8
    Oct 19, 2022 at 8:51
  • Please also list the version of siunitx. (as pdflatex, kpathsea, latexmk versions are irrelevant). Perhaps even post the log from your compilation of the MWE.
    – daleif
    Oct 19, 2022 at 9:00
  • Also note that your second image is clearly not using the same font as you use in the MWE, please make sure they match.
    – daleif
    Oct 19, 2022 at 9:08
  • 1
    After some more examination, I figured out that there must be some font not behaving well in TeXLive 2022. Colleagues confirmed that 2021 and 2020 works ok.
    – gasar8
    Oct 19, 2022 at 10:04

2 Answers 2

1

It seems a bad misfeature in NewTX that the plus sign has smaller width than the minus sign.

You can fix it by redefining + in math mode so that it uses a box as wide as the minus sign.

\documentclass[10pt]{article}
\usepackage{siunitx, booktabs}
\usepackage{newtxtext, newtxmath}

\makeatletter
\newcommand{\wellsizedplus}{\mathbin{\mathpalette\wellsizedplus@\relax}}
\mathchardef\standardplus=\mathcode`+
\newcommand{\wellsizedplus@}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1-$}%
  \makebox[\wd\z@]{$\m@th#1\standardplus$}%
  \endgroup
}
\begingroup\lccode`~=`+ \lowercase{\endgroup\protected\def~}{\wellsizedplus}
\AtBeginDocument{\mathcode`+="8000 }

\begin{document}

\renewcommand{\arraystretch}{1.2}

\sisetup{round-mode=places, round-precision=3, retain-explicit-plus}
\begin{tabular}{
  c
  S[table-format=1.3]
  S[table-format=1.3]
  r
  r
}
\toprule

One & {Two} & {Three} &
  \multicolumn{1}{c}{$\pm 1\sigma$} &
  \multicolumn{1}{c}{$\pm 2\sigma$} \\
\midrule
1400  & 0.2469 & 0.2494 & \(^{\num{+0.1462}}_{\num{-0.2217}}\) & \(^{\num{+0.7946}}_{\num{-0.7372}}\) \\
2200  & 0.1433 & 0.1449 & \(^{\num{+0.3306}}_{\num{-0.2372}}\) & \(^{\num{+0.5893}}_{\num{-0.6317}}\) \\
3400  & 0.3360 & 0.3396 & \(^{\num{+0.2250}}_{\num{-0.5221}}\) & \(^{\num{+0.8784}}_{\num{-0.8279}}\) \\

\bottomrule

\end{tabular}

\end{document}

enter image description here

Note the table-format options and also that the last two columns are not S type.

0

Edit:
Now, after edited question is clear what you after. Showed table (only first two row) you can reproduce by:

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

\begin{document}
\setlength\extrarowheight{2pt}
\sisetup{retain-explicit-plus}
\begin{tabular}{S[table-format=4.0]
            *{2}{S[round-mode=places,
                   round-precision=3,
                   table-format=1.3]}
            *{2}{S[round-mode=places,
                   round-precision=3,
                   table-format=-1.3]}}
    \toprule
{One}   &   {Two}   &  {Three}  &   {$\pm 1\sigma$} &   {$\pm 2\sigma$} \\
    \midrule
4100    &   0.0667  &   0.0493  & $^{\num{+0.0807}}_{\num{-0.104}}$ & $^{\num{+0.6094}}_{\num{-0.504}}$  \\
    \addlinespace
5100    &   0.0334  &   0.0453  & $^{\num{+0.0662}}_{\num{-0.204}}$ & $^{\num{+0.0662}}_{\num{-0.403}}$  \\
    \bottomrule
\end{tabular}
\end{document}

enter image description here

Addendum:
With use of the tabularray package the vertical space between rows is better and table body code a bit shorter too:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}

\begin{document}
\sisetup{ round-mode=places,
          round-precision=3,
          retain-explicit-plus}
\begin{tblr}{colspec = { S[table-format=4.0,
                           round-mode=none,
                           round-precision=0]
                    *{2}{S[table-format=1.3]}
                    *{2}{Q[c, si={table-format=-1.3}, mode=math]}
                        },
                 row{1} = {guard},
                 measure=vbox}
    \toprule
One     &   Two     &   Three   &   \pm 1\sigma &   \pm 2\sigma     \\
    \midrule
4100    &   0.0667  &   0.0493  & ^{\num{+0.0807}}_{\num{-0.104}}   & ^{\num{+0.6094}}_{\num{-0.504}}  \\
5100    &   0.0334  &   0.0453  & ^{\num{+0.0662}}_{\num{-0.204}}   & ^{\num{+0.0662}}_{\num{-0.403}}  \\
4100    &   0.0667  &   0.0493  & ^{\num{+0.0807}}_{\num{-0.104}}   & ^{\num{+0.6094}}_{\num{-0.504}}  \\
5100    &   0.0334  &   0.0453  & ^{\num{+0.0662}}_{\num{-0.204}}   & ^{\num{+0.0662}}_{\num{-0.403}}  \\
    \bottomrule
\end{tblr}
\end{document}

enter image description here

7
  • This is not desired, since this is only the MWE. I need two numbers in one row, since the table has many more columns with one number per row. This would potentially work if I would do multirows on all others, but this is not what I want.
    – gasar8
    Oct 19, 2022 at 13:08
  • Sorry, your question is than unclear. Please show a sketch of desired result. If you need more columns, just add them to shopwed table.
    – Zarko
    Oct 19, 2022 at 13:14
  • Sorry. The excerpt of the desired table is added to the bottom of the question. Note that it is fine on MWE, but not if there is a styling of a bigger project applied. I assume there is something wrong with TeXLive 2022 and our styling, because 2021 works ok even within the project.
    – gasar8
    Oct 19, 2022 at 13:58
  • @gasar8, you only define number of columns and than populate them with content, I will show this in edited answer (it will appear ASAP).
    – Zarko
    Oct 19, 2022 at 14:10
  • Sorry if I am not clear, but I know how to do that. The only problem is that the last column is not aligned on decimal point in the bigger project if run with TeXLive 2022.
    – gasar8
    Oct 19, 2022 at 14:13

You must log in to answer this question.

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