2

Here is my LaTeX code:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath,amsfonts,amssymb}
\begin{document}
\begin{align}
DS &= \frac{100}{l} * \sum_{t=1}^{l}d_t &&  d_t &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & sonst\end{array}\right.\\
WDS &=\frac{\sum_{t=1}^{l}d_t|y_t-\hat{y}_t|}{\sum_{t=1}^{l}d_t'|y_t-\hat{y}_t|} && d_t &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & sonst\end{array}\right. &&\\
d_t' &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
0, & sonst\end{array}\right.\\
\end{align}
\end{document}

I want an output including 2 equations: In the first row DS, with the condition dt, and in the second row WDS with dt and d't (dt and d't aligned)

This picture shows the output of the code:

This is the actual output of the latex code

The desired form of the output is

enter image description here

andrew
  • 23

2 Answers2

2

Like this? Just add some more &s to align.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\DeclareMathOperator{\ds}{DS}
\DeclareMathOperator{\wds}{WDS}
\begin{document}
\begin{align*}
\ds &= \frac{100}{l}\cdot\sum_{t=1}^{l}d_t &&&  d_t &= 
\begin{cases}
0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & \text{sonst}
\end{cases}\\
\wds &=\frac{\sum_{t=1}^{l}d_t|y_t-\hat{y}_t|}{\sum_{t=1}^{l}d_t'|y_t-\hat{y}_t|} &&& d_t &= 
\begin{cases}
0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & \text{sonst}
\end{cases} &&\\
&&&&d_t' &= 
\begin{cases} 
0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
0, & \text{sonst}
\end{cases}\\
\end{align*}

\end{document}

enter image description here

  • I use \cdot as a substitution of *.
  • I use cases instead of array.
  • I use \text{sonst} instead of sonst (which is understood as s × o × n × s × t).
  • I use \DeclareMathOperator for \ds and \wds, thanks to @sheß for pointing that out!
  • I'd also use \text{..} for DS and WDS... the kerning for WDS looks especially weird. I wonder what could be done to make people use \text{..} more consistently in formulas. – sheß Apr 02 '19 at 09:36
  • 1
    @sheß Thanks to pointing out that. But I don't think DS and WDS need \text, they need \DeclareMathOperator. –  Apr 02 '19 at 09:37
  • Why? What's the difference? I tried to look it up here and aside from the fact that \DeclareMathOperator is -- by name -- intended for operators and not variables. I don't see what the differences is. – sheß Apr 02 '19 at 09:45
  • 1
    @sheß IMHO \text is not for things like this. The reason I use \DeclareMathOperator is that this command is for things like \sin, \cos, etc., and I think "DS" and "WDS" are similar. –  Apr 02 '19 at 09:47
  • Mh, interesting, I didn't find much on this, except the unsatisfactory (https://tex.stackexchange.com/questions/6087/two-letter-variable-names) and a few very localized mainly opinion-based questions. So I created this: https://tex.stackexchange.com/questions/482743/typesetting-multi-letter-varaible-names-in-math-declaremathoperator-or-text – sheß Apr 02 '19 at 10:04
  • 1
    @sheß and I just upvoted it. –  Apr 02 '19 at 10:05
0

Like so?

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{align}
\text{DS} &= \frac{100}{l} \cdot \sum_{t=1}^{l}d_t &  d_t &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & \text{sonst}\end{array}\right.\\
\text{WDS} &=\frac{\sum_{t=1}^{l}d_t|y_t-\hat{y}_t|}{\sum_{t=1}^{l}d_t'|y_t-\hat{y}_t|} & d_t &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
1, & \text{sonst}\end{array}\right. &&\\
&&d_t' &= \left\{\begin{array}{ll} 0, & (\hat{y}_t - \hat{y}_{t-1})(y_t - y_{t-1}) \\
0, & \text{sonst}\end{array}\right.
\end{align}
\end{document}
\end{document}

I also changed your * to \cdot, because I think t looks nicer. And more importantly I wrapped DS , WDS, and sonst into \text{ }. If you don't do this, LaTeX will think you're typeseting s*o*n*s*t which will make the spacing between letters weird (you can see that by typesetting \emph{beispiffel} $beispiffel$)

enter image description here

sheß
  • 3,622