7

I am trying to add the definitions for my equation in my document. I know this has been asked before and I found a beautiful solution. But it is just not working for me.

This is what I found

    \documentclass{article}
    \usepackage{amsmath}% http://ctan.org/pkg/amsmath
    \usepackage{array}% http://ctan.org/pkg/array
    \begin{document}
        \begin{gather}
      P_{xi}=\overline{U}_x+\sigma_x
             \frac{\sum_k^{Nu}D_{kx}\times\left(\frac{S_{ki}-\overline{U}_k}{\sigma_k}\right)}
                  {\sum_k^{Nu}D_{kx}},
    \intertext{Where:}
      \begin{tabular}{>{$}r<{$}@{\ :\ }l}
        P_{xi} & is the predicted rate for user~$x$ on item~$i$ \        S_{ki} & is the rate of song~$i$ given by user~$k$ \        D_{kx} & the correlation between user~$x$ and user~$k$ \        \overline{U}_x & the average rate over user~$x$ \        \overline{U}_k & the average rate over user~$k$ \        \sigma_x & is the standard deviation of all the rates of user~$x$
      \end{tabular}\nonumber
    \end{gather}
\end{document}

and this is what I tried to make of it:

\begin{gather}
    dN/d(d_{p}) = kd_{p}^{\delta},
\intertext{Where:}
\begin{tabular}{>{$}r<{$}@{\ :\ }l}
 dN  : number of particles per unit water volume in the size range d p  to  [d p +d(d p )] \                                       
 k   :  (= constant) depending on the particle concentration \
 \delta   :   (< 0) descriptor of the distributions' spectral slope.  
\end{tabular}\nonumber
\end{gather}

If I put the "&", latex tells me, that I don´t have enough columns. Also the "\" is not showing up in red. I think the problem lies in the {>{$}r<{$}@{\ :\ }l} part. But I don´t understand what is going on in this.

Help will be very much appreciated.

Thanks

David Carlisle
  • 757,742
Miklagard
  • 101
  • 1
    Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Also, whay are you using tabular in math mode - you could just use array instead. Or, better still, ust move the tabular out of math mode. – Peter Grill May 05 '17 at 11:05

3 Answers3

5

You have been bitten by the infamous \\ bug of the site, see Double backslashes disappear from code

You copied the code from

https://tex.stackexchange.com/a/53483/4427

which was affected by the bug. Here is the fixed code.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\begin{document}

\begin{gather}
      P_{xi}=\overline{U}_x+\sigma_x
             \frac{\sum_k^{Nu}D_{kx}\times\left(\frac{S_{ki}-\overline{U}_k}{\sigma_k}\right)}
                  {\sum_k^{Nu}D_{kx}},
    \intertext{Where:}
      \begin{tabular}{>{$}r<{$}@{\ :\ }l}
        P_{xi} & is the predicted rate for user~$x$ on item~$i$ \\
        S_{ki} & is the rate of song~$i$ given by user~$k$ \\
        D_{kx} & the correlation between user~$x$ and user~$k$ \\
        \overline{U}_x & the average rate over user~$x$ \\
        \overline{U}_k & the average rate over user~$k$ \\
        \sigma_x & is the standard deviation of all the rates of user~$x$
      \end{tabular}\nonumber
    \end{gather}
\end{document}

enter image description here

The fixed code for your attempt should be

\begin{gather}
    dN/d(d_{p}) = kd_{p}^{\delta},
\intertext{Where:}
\begin{tabular}{>{$}r<{$}@{\ :\ }l}
 dN     & number of particles per unit water volume in the \\
 \multicolumn{1}{c}{} & size range $dp$  to  $[dp+d(dp)]$ \\
 k      & (constant) depending on the particle concentration \\
 \delta & ($<0$) descriptor of the distributions' spectral slope.
\end{tabular}\nonumber
\end{gather}

enter image description here

egreg
  • 1,121,712
  • This worked! Thank you! Thank you! Thank you so, so much!!! – Miklagard May 05 '17 at 12:49
  • IMHO, in this case it seems that \shortintertext might be better. – Peter Grill May 05 '17 at 22:33
  • Do I need a package for \shortintertext. It shows up in red, when I try. Also, I tried to apply this version of the equation for another one and get the message "Missing $ inserted. \end{gather}". What does that mean? Plus, if I try this with a third equation, it has the definition centered. – Miklagard May 06 '17 at 13:20
  • @Miklagard You need mathtools – egreg May 06 '17 at 13:27
  • I use the package mathtools, but I still get the error message plus this one: Package inputenc Error: Unicode char − (U+2212)(inputenc) not set up for use with LaTeX. \end{gather}. – Miklagard May 08 '17 at 11:10
4

Here is one way that might be useful:

enter image description here

Using the [t] option on tabular yields better spacing above the tabular as per campa's comment. However, according to egreg there is a potential problem with this affecting paragraph spacing but I was unable to see this problem so have posted: Unable to duplicate problem: Using [t] option on tabular affect paragraph spacing.

Code:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{array}% http://ctan.org/pkg/array
\begin{document}
\[
    dN/d(d_{p}) = kd_{p}^{\delta},
\]
where:

\begin{tabular}[t]{r@{}l} $dN$ &: number of particles per unit water volume in the size range $d p$ to $[d p +d(d p )]$ \
$k$ &: (= constant) depending on the particle concentration \ $\delta$ &: $(< 0)$ descriptor of the distributions' spectral slope. \end{tabular} \end{document}

Peter Grill
  • 223,288
  • @campa: Good suggestion. Have updated answer. – Peter Grill May 05 '17 at 12:07
  • This way the spacing becomes bad at the end. Try adding a paragraph. – egreg May 05 '17 at 12:09
  • @egreg sure? I see no difference with [t] or without. Though [b] gives better spacing at the end, that's surely true. Maybe is a couple of \smallskip (before and after) better? – campa May 05 '17 at 12:13
  • @campa Very sure, even without trying it. – egreg May 05 '17 at 12:27
  • @egreg: I can't seem to reproduce the problem you mention. I tried a short paragraph with preceeded with and without a blank line and tried lipsum[1] for a longer paragraph. Is there a reference for that on TeX.SE? A quick search did not show anything obvious to me. – Peter Grill May 05 '17 at 22:33
  • @PeterGrill Try with a line with all x’s after the tabular (and a blank line). – egreg May 05 '17 at 22:36
  • @egreg: I still get identical results. I will post a question so that there can be reference for this issue. – Peter Grill May 05 '17 at 22:40
  • @PeterGrill No need to: between the tabular and the next paragraph, \lineskip glue is inserted, so there's no guarantee that the two baselines are set \baselineskip apart. Try setting \lineskip=2cm and you'll see what I mean. It's a very well known problem. See https://tex.stackexchange.com/questions/34971/ for a related problem (the nature is the same). – egreg May 05 '17 at 22:45
  • Already posted Unable to duplicate problem: Using [t] option on tabular affect paragraph spacing. But, with \lineskip=2cm, the only difference I see is that there is less spacing above the tabular with the [t] option. Is this specifc issue a minipage related one? I don't see it affecting the paragraph spacing. – Peter Grill May 05 '17 at 22:57
1

Another solution, based on framed and a description environment (more satisfying, semantically). Also, I think the d for the differential and the d in d_p are a somewhat confusing notation, so I decided to have the differential ‘d’ upright, with a macro found on this site

\documentclass{article}

\renewcommand*{\d}{\mathop{\kern0pt\mathrm{d}}\!{}}

\usepackage{enumitem, framed}
\newenvironment{myleftbar}{%
      \def\FrameCommand{{\hspace{0.8cm}\vrule width 0.5pt}\hspace{6pt}}%\
      \MakeFramed {\advance\hsize-2\width \FrameRestore}\noindent\hspace{- 0.4em}}%
     {\endMakeFramed}
\newenvironment{eqdescription}{%
\myleftbar
\llap{\makebox[1.4cm][l]{where: }}\vspace*{-\dimexpr\baselineskip + \topsep}\strut
\description[font=\normalfont, labelwidth=0.5cm, align=right, leftmargin=!, itemsep=0pt]
}
{%
\enddescription\vspace*{-\topsep}
\endmyleftbar}

\begin{document}
\[
    \d N/\d(d_{p}) = kd_{p}^{\delta},
\]

\begin{eqdescription}
\item[$\d N$:] number of particles per unit water volume\\ in the size range $d_p$ to $[d_p +\d(d_p )]$,
\item[$k$:] (= constant) depending on the particle concentration,
\item[$\delta$:]$(< 0)$ descriptor of the distributions' spectral slope.
\end{eqdescription}

\end{document} 

enter image description here

Bernard
  • 271,350