10

I'd like to get something like this: [-40 ; 80] °C

Instead I'm getting:

enter image description here

Below is a MWE. I've tried to include all necessary packages for siunitx, as written in its documentation; there are more, perhaps they are conflicting with the ones siunitx requires...

\documentclass[a4paper,12pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[italian]{babel}

\usepackage{amssymb, amsmath, amsfonts, xfrac, mathpazo} %all maths
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{enumerate}
\usepackage{outlines}
\usepackage{enumitem}
\setlist[enumerate,2]{label= \roman*)}
\setlist[enumerate,3]{label=\textbf{\alph*})}
\usepackage{siunitx}
 \sisetup{range-phrase = \ ;\ ,
          range-units  = brackets,
          list-units   = brackets}
\usepackage{listings} %useful for siunitex
\usepackage{cancel}
\usepackage{blindtext}
\usepackage{hyperref}
\hypersetup{pdfstartview=FitH} 
\usepackage[italian]{cleveref} 

\begin{document}
$\SIrange{-40}{80}{\celsius}$
\end{document}
  • For your example you just need the siunitx package. It does not need anything else. I guess you misunderstood Joseph Wright. He writes that you need these packages installed in order to compile his documentation. But you can just type texdoc siunitx in a terminal and get it nicely done shown in your pdf-reader. – LaRiFaRi Apr 19 '14 at 0:09
10

The author of siunitx is English, so “bracket” doesn't mean the same as on the other side of the pond. By default, brackets are parentheses, but it's possible to customize them.

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{siunitx}
\sisetup{
  range-phrase = \ {;}\ ,
  range-units  = brackets,
  open-bracket = [,
  close-bracket= ],
}

\begin{document}
$\SIrange{-40}{80}{\celsius}$
\end{document}

The {;} trick makes for symmetric space on either side.

enter image description here

If you want to apply the square brackets only for \SIrange, then you can redefine the command to locally do the setting:

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{siunitx}
\sisetup{
  range-phrase = \ {;}\ ,
  range-units  = brackets,
}

\ExplSyntaxOn
\RenewDocumentCommand \SIrange { O{} m m m } {
  \leavevmode
  \group_begin:
     \keys_set:nn { siunitx } { open-bracket = [,  close-bracket= ], #1}
     \__siunitx_range_unit:nnnn {#4} { open-bracket = [,  close-bracket= ], #1} {#2} {#3}
  \group_end:
}
\ExplSyntaxOff

\begin{document}
$\SIrange{-40}{80}{\celsius}$

\SIlist[list-units = brackets]{2;4;6;8}{\tesla}

\num[bracket-negative-numbers]{-15673}

\num{1 \pm 2i e3}
\end{document}

enter image description here

  • 1
    'Bracket' is a generic term in UK English: 'parenthesis' is specific to () :-) – Joseph Wright Apr 18 '14 at 16:25
  • @JosephWright May I know how to enclose the unit itself with brackets? – Diaa Oct 30 at 12:44
  • Would you please explain what the backslashes in range-phrase = \ {;}\ , are used for? – Diaa Nov 3 at 20:23
  • 1
    @Diaa “Space, semicolon, space”. – egreg Nov 3 at 21:11
2

The version shown by egreg is very elegant but also quite harsh to other brackets you might want to use. It's not clear from your question, if you would like to have the following behaviours, too:

% arara: pdflatex

\documentclass{scrartcl}
\usepackage{siunitx}
\sisetup{
  range-phrase = \ {;}\ ,
  range-units  = brackets,
  open-bracket = [,
  close-bracket= ],
}

\begin{document}\noindent
\SIrange{-40}{80}{\celsius}\\
\SIlist[list-units = brackets]{2;4;6;8}{\tesla} \\
\num[bracket-negative-numbers]{-15673} \\
\num{1 \pm 2i e3} \\
\end{document}

enter image description here

If you really just want to change the behaviour of the range case shown in your question, I would recommend to redefine this command.

% arara: pdflatex

\documentclass{scrartcl}    
\usepackage{siunitx}
\renewcommand{\SIrange}[3]{\lbrack\num{#1}\ {;}\ \num{#2}\rbrack\,\si{#3}}

\begin{document}\noindent
$\SIrange{-40}{80}{\celsius}$\\
\SIrange{-40}{80}{\celsius}
\end{document}

This also yields

enter image description here

but does not touch all the other cases.

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.