3

To avoid writing down all the units and the associated powers, I wanted to start to use the siunitx package but I have a problem. In fact :

  • The pressure is \SI{10}{\mega\pascal} = "The pressure is 10 MPa"
  • The pressure is 10 \mega\pascal = "The pressure is 10"

In other words, I can't write the units without using \SI{expression}{units}, which is quite restrictive. Does someone have any idea to fix it ?

Thanks in advance.

2
  • 4
    Welcome to TeX.SX! That's by design: siunitx's units only work inside siunitx's commands. \SI{10}{\mega\pascal} is the correct syntax and you should use that Apr 19, 2021 at 21:08
  • 4
    You can use units with \si {\mega\pascal}, or, simpler, \si{\MPa}, but to be sure to have the correct spacing between number and unit, it's better to use \SI{10}{\MPa}.
    – Bernard
    Apr 19, 2021 at 21:18

3 Answers 3

9

You can load the package with option free-standing-units, then define

\DeclareSIUnit\megapascal{\mega\pascal}

to allow \megapascal in document scope. You might also want unit-optional-argument to allow \megapascal[10], or space-before-unit to allow 10\megapascal to work.

I recommend the standard interface in which units are an argument to \SI.

2
  • I'm assuming the unit-optional-argument method would produce the space in 10 000 and make a box with the number and unit together (?), for example, where 10\megapascal would not? Apr 20, 2021 at 22:02
  • @likethevegetable Yes
    – Joseph Wright
    Apr 20, 2021 at 22:24
0

I think I found the answer:

\usepackage{siunitx}

\sisetup{decimalsymbol=comma,expproduct=.,seperr}

I don't know why it works, but it works! I took all the packages of a friend that could do it and removed it one after the other to figure out that the \sisetup command allows me to do what I wanted.

1
  • The \sisetupcommand you used here contains options that were only available in version 1 of the siunitx package. If you use this with a more recentversion, you will get a corresponding warning message, such as "Version 1 option ... detected." Internally, the siunitx package now seems to use version-1-compatibility. Thus, you can achieve the same behavior, if you use \usepackage[version-1-compatibility]{siunitx} instead of the two lines of code you showed in your answer. However, Joseph Wright's answer is definitely preferrable.
    – leandriis
    Apr 25, 2021 at 7:40
-1

To only get the units, you can do:

\SI{}{\mega\pascal}

or (the more correct one):

\si{\mega\pascal}

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.