Edit Adding equation numbers and looking after \si{...}
The code below defines a command \ExplainedFormula
that when given
\ExplainedFormula{\Re = \dfrac{v\cdot d}{\nu}}
{\Re: Reynolds number:,
v: velocity of the fluid: \milli\meter\per\second,
d: characteristic linear dimension: \milli\meter,
\nu: kinematic viscosity: \milli\meter\squared\per\second
}
Nulla malesuada porttitor diam. Donec felis erat, congue non,
volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum
felis. Donec nonummy pellentesque ante.
\ExplainedFormula*{\Re = \dfrac{v\cdot d}{\nu}}
{\Re: Reynolds number:,
v: velocity of the fluid: \milli\meter\per\second,
d: characteristic linear dimension: \milli\meter,
\nu: kinematic viscosity: \milli\meter\squared\per\second
}
will 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:
\documentclass{article}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{xparse}
\renewcommand\Re{\mathop{\textrm{Re}}}
\def\Explain#1:#2:#3!!!{% \Explain variable : description : unit !!!
$#1$ & #2 $[\if\relax\detokenize{#3}\relax-\else\si{#3}\fi]$
\\
}% add a line of explanation
\NewDocumentCommand\ExplainedFormula{ s m m }{%
% usage: \ExplainedFormula{formula}{csv explanation}
\begin{center}
\hbox to\textwidth{%
\IfBooleanF{#1}{\refstepcounter{equation}\rlap{(\theequation)}}
\hfil$\displaystyle#2$
\hfil\renewcommand*\do[1]{\Explain##1!!!}%
\begin{tabular}{r@{\dots}l}\docsvlist{#3}\end{tabular}
\hfil%
}%
\end{center}
}
\begin{document}
\ExplainedFormula{\Re = \dfrac{v\cdot d}{\nu}}
{\Re: Reynolds number:,
v: velocity of the fluid: \milli\meter\per\second,
d: characteristic linear dimension: \milli\meter,
\nu: kinematic viscosity: \milli\meter\squared\per\second
}
Nulla malesuada porttitor diam. Donec felis erat, congue non,
volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum
felis. Donec nonummy pellentesque ante.
\ExplainedFormula*{\Re = \dfrac{v\cdot d}{\nu}}
{\Re: Reynolds number:,
v: velocity of the fluid: \milli\meter\per\second,
d: characteristic linear dimension: \milli\meter,
\nu: kinematic viscosity: \milli\meter\squared\per\second
}
\end{document}
Some words of explanation:
- The
\ExplainedFormula
macro is defined using \NewDocumentCommand
from the xparse package. The s 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.
- The mandatory arguments of
\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
- The comma separated list of explanations is processed using
\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.
- Everything is thrown inside an
\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 spacing
- I have replaced
Re
by \Re
, which is given by \renewcommand\Re{\mathop{\textrm{Re}}}
- I don't really like the
\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...
Best Answer
Like this?
Of course, since this is an exercise, I shouldn't disclose the code I produced the image with.
;-)
The basis is, of course,
\resizebox{1}[1.6]{...}
from thegraphicx
package. However, proper positioning is not really easy, but not terribly difficult either.Well here's the commented code
I'm not sure if a student is really supposed to know all that, but maybe the instructor will learn something.
;-)