8

I am trying to create a big table without leading zeros using siunitx \num{}. Namely, I have a bunch of number formated like this:

0.001
0.1
1.000

and I want to remove the 0. part. So the output would be:

.001
.1
1.000

It should be the opposite of add-integer-zero option (something like remove-integer-zero). I have triyed lots of \sisetup configuration without luck. All question in tex exchange seems to be the opposite to what I want. Any idea of it is possible?

Thanks in advance.

12
  • Please show us an MWE showing your table. Do you need any other siunitx actions like aligning? – LaRiFaRi Apr 21 '14 at 11:54
  • 6
    Removing the leading zero is not recommended. – egreg Apr 21 '14 at 12:02
  • Welcome to TeX.SX! – Heiko Oberdiek Apr 21 '14 at 12:11
  • 1
    \sisetup{add-integer-zero=false} is the way to remove the leading zero, but don't do it. – egreg Apr 21 '14 at 12:14
  • @egreg: add-integer-zero=false will not add an integer zero, .001 would be kept, but the option does not remove a zero from the input. AFAIK the requested feature is not supported by siunitx. – Heiko Oberdiek Apr 21 '14 at 12:19
4

I agree with the comments about this not being a good idea. But having said that, here's an approach, using the expl3 syntax that siunitx is built upon:

\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn

\NewDocumentCommand\trimleadingzero{m}{%%
  \fp_compare:nTF { 0 < \fp_abs:n { #1 } < 1 }
    { 
      \__trimleadingzero:n {#1}
    }
    { #1 }
}

\cs_new_protected:Npn \__trimleadingzero:n #1 {
  \seq_set_split:Nnn \l_ae_integer_decimal_parts_seq {.} {#1}
  \fp_compare:nF {#1>0}
    { - }
  .\seq_item:Nn \l_ae_integer_decimal_parts_seq {2}
}

\ExplSyntaxOff
\begin{document}

\SI[add-integer-zero=false,parse-numbers=false]{\trimleadingzero{0.03}}{}

\SI[add-integer-zero=false,parse-numbers=false]{\trimleadingzero{-0.03}}{}

\end{document}

enter image description here

7
  • Thanks for the code but I am afraid that does not work in my setup. Will I need a special version of expl3? – cruzki Apr 22 '14 at 15:47
  • @cruzki The above code should work with the most recent version of LaTeX. You might want to update your system. – A.Ellett Apr 22 '14 at 18:03
  • I have test both in Texlive 2013 (up to date gentoo linux unstable) and MikTex 2.9 (windows 7). I have tested both pdflatex and lualatex without luck (the leading 0 is still presented). – cruzki Apr 22 '14 at 18:27
  • @cruzki If everything is up-to-date, then I'm not sure why it wouldn't work. Perhaps you should post a new question showing what you've tried so we can try to figure out why it's not working for you. I know that's a bit of a lame response, but without knowing more about what you're doing, it's hard to say. One thing you could try is add \listfiles in your preamble. That will inform you about versions of packages. When I do that it tells me that my version of expl3 is expl3.sty 2014/01/07 v4646 L3 Experimental code bundle wrapper – A.Ellett Apr 22 '14 at 19:00
  • The problem is that the example you have provide is not working (and I do not have any experience with expl3 to debug the problem). It seems that my expl3 is almost a yera old compared with yours. I will try to update it. \listfiles expl3.sty 2013/03/14 v4469 L3 Experimental code bundle wrapper – cruzki Apr 22 '14 at 19:10

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.