6

Today I started practicing with siunitx. It is a bit fun, but I arrive at some troubles.

I have a stats table where I want to have a literal period, meaning no estimate was obtained, in some cells. I also have some cells where the numbers might be wrapped in parentheses and a few where they have asterixes. I've solved those problems, so the mre below does not emphasize them.

It is not allowed to have a cell with "." by itself. I get the "invalid-value" error from siunitx.

One workaround is to wrap the period in a multicolumn, that does not give the error. But the output is not quite right either

\documentclass[11pt,letterpaper,english]{extarticle}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}

\usepackage{siunitx}
\sisetup{
    input-symbols = ()*,
    group-minimum-digits = 9
}

\begin{document}
\begin{tabular}{
  l
  S[table-format=1.3, table-align-text-post=false]
  S[table-format=1.3, table-align-text-post=false]
}
\hline
hello &1.333 &33.222\tabularnewline
goodbye &44.1 & \multicolumn{1}{c}{.} \tabularnewline
\hline
\end{tabular}

\end{document}

But, as you expect, the period is not aligned.

siunitx with a period in a cell

I don't have a strong reason to require them to be aligned, but it would be fun if I could do it :)

2 Answers 2

9

You could use a \phantom.

By the way, you declared table-format=1.3 but your numbers have 2 integer positions, I corrected in table-format=2.3, otherwise you have an Overfull hbox warning.

\documentclass[11pt,letterpaper,english]{extarticle}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}

\usepackage{siunitx}
\sisetup{
    input-symbols = ()*,
    group-minimum-digits = 9
}

\begin{document}
\begin{tabular}{
  l
  S[table-format=2.3, table-align-text-post=false]
  S[table-format=2.3, table-align-text-post=false]
}
\hline
hello &1.333 &33.222\tabularnewline
goodbye &44.1 & \multicolumn{1}{l}{\phantom{00}.} \tabularnewline
\hline
\end{tabular}
\end{document}

enter image description here

4
  • About your 1.3 comment: These tables are going to be written with R and numbers have maximum 3 decimal points, but in end might be integer, 1 or 2 decimal points. Should I worry about warning? I just realized left may have more digits too.
    – pauljohn32
    Oct 9, 2018 at 12:01
  • @pauljohn32 table-format=2.3 means that the number can have at the maximum 2 integer and 3 decimals, if some numbers have less, it doesn't matter. The number of digit in my \phantom command must be equal to the maximum number of integers, in your case 2.
    – CarLaTeX
    Oct 9, 2018 at 12:26
  • +1 Thanks for the idea. I'm not marking it as a solution for me because I am not able to say in advance how many digits there will be on the left side, so pre-calculating phantom is not possible. I'm trying to make this work without inserting table-format, but, as you mention, the correct alignment seems to depend on it.
    – pauljohn32
    Oct 11, 2018 at 15:06
  • @pauljohn32 You are obliged to put a number of digit in table-format=X.Y, the X tells you how many digits you have to put in \phantom{...}. If X=1, you write \phantom{0}, if X=2, you write \phantom{00}, X=3, you write \phantom{000}. I hope it's clearer now.
    – CarLaTeX
    Oct 11, 2018 at 15:11
5

similarly to CarLaTeXanswer:

\documentclass[11pt,letterpaper,english]{extarticle}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}

\usepackage{siunitx}
\sisetup{
    input-symbols = ()*,
    group-minimum-digits = 9
}

\begin{document}

\begin{tabular}{
  l
  S[table-format=2.3, table-align-text-post=false]
  S[table-format=2.3, table-align-text-post=false]
}
\hline
hello   &    1.333  &    33.222             \tabularnewline
goodbye &   44.1    &    {.\hphantom{2}}    \tabularnewline
\hline
\end{tabular}

\end{document}

enter image description here

2
  • ups, you are right! this one i prepare for another question ... :-(, i will correct this asap
    – Zarko
    Oct 9, 2018 at 5:25
  • +1 Thanks for the idea. I'm not marking it as a solution for me because I am not able to say in advance how many digits there will be on the left side. I'll keep testing.
    – pauljohn32
    Oct 11, 2018 at 15:07

You must log in to answer this question.

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