I am trying to write an equation -first order conditions of a Lagrangian- in a multiline open bracket but due the length of the equation it doesn't look right. I am using equation* and cases from amsmath. How do I insert line breaks within each line so that the whole thing looks better?
\documentclass{article}
%packages
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\title{To be determined later}
\date{December 2024}
\begin{document}
\maketitle
\begin{equation*}
\dfrac{\partial \mathcal{L}}{\partial \psi_k} =
\begin{cases}
\frac{1}{n} - \delta_1 H_2(\psi_2,\psi_1) +\mu_2\delta_2 & \mathrm{if} \, k = 1 \\
\frac{1}{n} - \delta_1 H_1(\psi_2,\psi_1) -\delta_2 H_2(\psi_3,\psi_2) - (\delta_1+\delta_2)\mu_2 + \delta_3\mu_3 & \mathrm{if} \, k = 2 \\
\frac{1}{n} - \delta_{k-1} H_1(\psi_k,\psi_{k-1}) -\delta_k H_2(\psi_{k+1},\psi_k) + \delta_{k-2}\mu_{k-1}- (\delta_k+\delta_{k-1})\mu_k + \delta_{k+1}\mu_{k+1} & \mathrm{if} \, 3\le k \le n-2 \\
\frac{1}{n} - \delta_{n-2}H_1(\psi_{n-1},\psi_{n-2}) -\delta_{n-1}H_2(\psi_n,\psi_{n-1})+\delta_{n-3}\mu_{n-2}-(\delta_{n-1}+\delta_{n-2})\mu_{n-1} & \mathrm{if} \, k = n-1\\
\frac{1}{n} - \delta_{n-1}H_1(\psi_n,\psi_{n-1}) + \delta_{n-2}\mu_{n-1} & \mathrm{if} k = n
\end{cases}
\end{equation*}
\end{document}
Edit: Here is the document's settings and the packages I use:
\documentclass{article}
%packages
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\title{To be determined later}
\author{Aref Sadeghi}
\date{December 2024}
\begin{document}
Here is a picture of what the equation looks like now:
Obviously 3 is the page number so the equation is eating into the right margin