Weird placement with align

I want to denote the quantile regression loss, close to the notation in the IQN-paper https://arxiv.org/pdf/1806.06923.pdf (pdf page 3)

I have this code:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bbm}

\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\newcommand{\Idf}{\mathbbm{1}} % indicator function
\begin{document}

\begin{align}
\rho^\kappa_\tau(\delta_{ij}) &= \abs{\tau - \I(\delta_{ij}<0)} \frac{H_\kappa(\delta_{ij})}{\kappa}, \qquad \text{with} \\
\H_\kappa(\delta_{ij}) &=
\begin{cases}
\frac{1}{2}\delta_{ij}^2 & \text{if} \; \abs{\delta_{ij}} \leq \kappa \\
\kappa (\abs{\delta_{ij}}-\frac{1}{2}\kappa) & \text{otherwise}
\end{cases}
\end{align}

\end{document}


Which produces this output:

As can be seen, part of the equations falls of the screen. and the first line of the equation is also placed weirdly, not in the centre of the screen. I tried to remove the \begin{cases} \end{cases} to something simpler and stuff still did not align well so I have the feeling it is due to the align function and not the cases.

• Please make your example into a complete example that others can just copy and test as is. Especially since the code you provide does not compile and thus in most editors latex will make a guess to make the compilation finish and theses guesses aren't always good. Thus never ignore compilation errrors. – daleif Sep 14 '20 at 12:45
• Thanks for your response. I changed my post such that the equation can be compiled. – Rens Sep 14 '20 at 12:52
• Your code produces an error ! Undefined control sequence. <argument> \tau - \I  after any error the pdf output is at best usable for debugging it is not intended to have usable layout – David Carlisle Sep 14 '20 at 12:54
• Moreover, you use H as well as \H, and \H causes another error. – gernot Sep 14 '20 at 12:55
• If I change \I to \Idf then you get the error ! Missing \$ inserted. – David Carlisle Sep 14 '20 at 12:55

1 Answer

When asking about an error it is best to show the error message from the log. The pdf output after any error is possibly useful as a debugging aid but not intended to have sensible layout.

If I fix your errors for \I which is undefined and \H which is a predefined accent then you get

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bbm}

\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\newcommand{\Idf}{\mathbbm{1}} % indicator function
\begin{document}

\begin{align}
\rho^\kappa_\tau(\delta_{ij}) &= \abs{\tau - \Idf(\delta_{ij}<0)} \frac{H_\kappa(\delta_{ij})}{\kappa}, \qquad \text{with} \\
H_\kappa(\delta_{ij}) &=
\begin{cases}
\frac{1}{2}\delta_{ij}^2 & \text{if} \; \abs{\delta_{ij}} \leq \kappa \\
\kappa (\abs{\delta_{ij}}-\frac{1}{2}\kappa) & \text{otherwise}
\end{cases}
\end{align}

\end{document}

• I would upvote your answer but I can't because I lack the reputation. I see that when I copy my code above to a new overleaf file I get error messages, but I did not get any error message when I compiled the equation in my main document. The \I was a mistake and should have been \Idf. The \H was the thing that caused the misplacement, I do not know why I denoted that. Thanks – Rens Sep 14 '20 at 13:02
• You must have had an error in the original, overleaf's error indicator is sadly rather small (it would be better if they did not show the pdf at all after an error) @Rens – David Carlisle Sep 14 '20 at 13:03