Adding section numbers to LaTeX floats numbering and other tips

I have been learning to use LaTeX for some time. Now I do most of my homework assignments in LaTeX. It wears quite well on me. I have encountered some issues, but most of the time I was able to find elegant solutions on TeX StackExchange. Here are a few tips I learned recently.

1. Show chapter or section numbers in equation/figure/table numbering

By default, LaTeX assigns equation numbers continually across different sections. If you need the equation to be numbered like “Eq. (3.5)” for the 5th equation in section 3, add this to the preamble:

\usepackage{amsmath}
\numberwithin{equation}{section}

To include also the subsection number, change the second line to

\numberwithin{equation}{subsection}

For figures and tables, it is similar.

\usepackage{amsmath}
\numberwithin{table}{section}
\numberwithin{figure}{section}

2. Scientific notation

The most elegant solution for scientific notation of numbers is to use the siunitx package.

\usepackage{siunitx}
...
\num{6.022e23}

\num{6.022e23} will be rendered as “6.022 × 1023”.

An alternative solution that does not depend on siunitx is:

\newcommand{\e}[1]{\ensuremath{\times 10^{#1}}}

This new command can be used like 6.022\e{23} to produce “6.022 × 1023”.

3. Upright differential operator

The differential operator d in dy / dx should be typeset in upright not italic shape, because it is not a variable (Beccari, 1997, TUGboat). The upright differential operator is not provided by the amsmath package, and to do it properly requires much low-level TeX programming due to spacing requirements. An out-of-the-box solution is to use the commath package, which provides the following commands:

There are also many other useful commands in this package.

Alternatively, a minimalist and nearly as good solution without using commath can be

\newcommand{\dif}{\mathrm{d}}
\newcommand{\Dif}{\mathrm{D}}
\newcommand{\od}[3][]{\ensuremath{\dfrac{\dif^{#1}#2}{\dif #3^{#1}}}}
\newcommand{\pd}[3][]{\ensuremath{\dfrac{\partial^{#1}#2}{\partial #3^{#1}}}}

References

  1. Beccari, C. (1997). Typesetting mathematics for science and technology according to ISO 31/XI. TUGboat, 18(1), 39–48. [link]