I've been using the below snippet for quite a while now to typeset important formulas in my documents. Until now I always copy-pasted the snippet and manually tweaked it until the spacing looked satisfying, but thats not why we're using LaTeX, right?
I'd love my snippet to even out spacings automatically (speaking the three marked spaces in the screenshot below should be the same size). Also some kind of macro that gives it a nicer input format with less redundant copy-pasting would be very nice (e.g. not having to type \vspace{\baselineskip}
, \begingroup
etc. every time). How can I achieve that? (I guess there are a lot more possibilities to polish it up so of course I'm open to other suggestions as well.)
\documentclass{article}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\vspace{\baselineskip}
\begingroup
\setlength{\tabcolsep}{0pt}
\begin{tabular}{crl}
\multirow{4}{.3\textwidth}{%
\centering
$Re = \dfrac{v\cdot d}{\nu}$
}
&$Re$&\dots Reynolds number $[-]$\\
&$v$&\dots velocity of the fluid $[\si{\milli\meter\per\second}]$\\
&$d$&\dots characteristic linear dimension $[\si{\milli\meter}]$\\
&$\nu$&\dots kinematic viscosity $[\si{\milli\meter\squared\per\second}]$
\end{tabular}
\endgroup
\vspace{\baselineskip}
\lipsum[2]
\end{document}
Best Answer
Edit Adding equation numbers and looking after
\si{...}
The code below defines a command
\ExplainedFormula
that when givenwill produce output like this:
By default,
\ExplainedFormula
will add an equation number and there is a starred version,\ExplainedFormula*
, that omits the equation number. The equation number is on the left, because this is where I always put it:) To put it on the right move the line\IfBooleanF{#1}{\refstepcounter{equation}\rlap{(\theequation)}}
so that it is after the last\hfil
in\ExplainedFormula
and change the\rlap
to\llap
...perhaps I should do this automatically... `Here is the full code:
Some words of explanation:
\ExplainedFormula
macro is defined using\NewDocumentCommand
from the xparse package. Thes m m
specification says that\ExplainedFormula
has three arguments, an optional*
and two mandatory arguments. The equation number is not printed if the*
is present.\ExplainedFormula
are for the formula and a comma separated list of "explanations". In turn, each "explanation" consists of a variable followed by:
followed by the explanation followed by another:
and then the\si
unit, which should be left blank if there is none (such as for the Reynolds number in the example above. The explanations should not contain!!!
as this is used by\Explain
to separate the formula and description components. The parts of the formulas should not be surrounded by$...$
as these are added by\ExplainedFormula
\docsvlist
from the etoolbox package together with some trickery (via\Explain
), to separate the formula component and the description. What happens is that\do
gets given each part of the comma separated descriptions, such as\Re: Reynolds number:
, and it gives this to\Explain
with!!!
added on the end so that the\Explain
macro knows where#3
ends.\hbox
of width\textwidth
and the components of the box are separated by\hfil
's, each of which will expand equally to fill up the available space. This should give the required equidistant spacingRe
by\Re
, which is given by\renewcommand\Re{\mathop{\textrm{Re}}}
\dots
in the explanation. I would probably add space either side, using something like@{\,\dots\,}
in the tabular definition, or instead use a colon or equals sign...