# Wrap text inside align environment

I have a bunch of text in an align environment which is overflowing to the margin. I would like to wrap it. Note I'm using a different document class than the one state below.

\documentclass[11pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
e_i &= \varepsilon(d_i, y_i) + \lambda\frac{1}{2} \vert w \vert ^2\label{eq:regularisation} \\
\textnormal{where:} & \nonumber \\
\varepsilon(\cdot) &= \textnormal{cost function} \nonumber \\
w &= \textnormal{weights matrix of connection from immediate right layer (towards output layer)} \nonumber
\end{align}

\end{document}


Only solution I can think of is:

    w &= \textnormal{weights matrix of connection from immediate right} \nonumber \\
&= \textnormal{layer (towards output layer)} \nonumber


Was hoping for a better solution as I don't want to have to change this every time the length of sentence changes.

• \parbox[t]{3cm}{weights of ....} – David Carlisle Apr 13 '18 at 15:47

\documentclass[11pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
e_i &= \varepsilon(d_i, y_i) + \lambda\frac{1}{2} \vert w \vert ^2\label{eq:regularisation} \\
\textnormal{where:} & \nonumber \\
\varepsilon(\cdot) &= \parbox[t]{5cm}{\raggedright cost function} \nonumber \\
w &= \parbox[t]{5cm}{\raggedright weights matrix of connection from immediate right layer (towards output layer)} \nonumber
\end{align}

\end{document}


You can use a tabular environment to have full control, and \shortintertext from mathtools:

\documentclass[11pt]{article}
\usepackage{mathtools}

\begin{document}

\begin{align}
e_i &= \varepsilon(d_i, y_i) + \lambda\frac{1}{2} \vert w \vert ^2\label{eq:regularisation} \\
\shortintertext{where:}
\varepsilon(\cdot) &= \textnormal{cost function} \nonumber \\
w &= \begin{tabular}[t]{@{}l@{}}weights matrix of connection from immediate right layer\\ (towards output layer)\end{tabular} \nonumber
\end{align}

\end{document}


• I like this solution because I don't have to guess the correct size needed for parbox. Thanks! What's the relevance of shortintertext? Why should I choose it over what I have i.e. using align? – user14492 Apr 18 '18 at 19:49
• It is aligned at the left margin, and the vertical spacing is shorter than with the standard \intertext. – Bernard Apr 18 '18 at 20:11