# How to left align the equation

I am using below equation in my document. By default, it is getting aligned at the center. I want to left-align the equation -- only this equation, not all equations in the document. Can anybody tell me how it can be done?

$$d_j = \begin{cases} newval_i, & \quad i = j\\ randval_k, & \quad k = j\\ bestval_j, & \quad \text{otherwise} \end{cases}$$

• Should all equations be left-aligned, or just this one? – Mico Apr 29 '17 at 16:10
• unrelated to alignment but that should be \mathit{newval}_i and similarly the other names, never use the default math italic for multi-letter words. – David Carlisle Apr 29 '17 at 16:19
• @Mico only this one – Atinesh Apr 29 '17 at 16:37
• @Atinesh - The fact that you only wish to left-align a single equation is very important, and unfortunately it's something that wasn't mentioned in your posting. It's not too late, though, to edit your posting and to clarify what it is you're trying to achieve. Go ahead. – Mico Apr 29 '17 at 16:47
• @Bobyandbob I have already gone through that post, It didn't solve my problem. – Atinesh Apr 29 '17 at 17:00

You can do that nesting your equations in a fleqn environment (from nccmath). This environment accepts an optional argument for the distance from the left margin ( 0 pt by default):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{mathtools, nccmath}

\begin{document}

$$d_j = \begin{cases} \text{newval}_i, & \quad i = j\\ \text{randval}_k, & \quad k = j\\ \text{bestval}_j, & \quad \text{otherwise} \end{cases}$$

\begin{fleqn}
\noindent\texttt{With fleqn: }
$$d_j = \begin{cases} \text{newval}_i, & \quad i = j\\ \text{randval}_k, & \quad k = j\\ \text{bestval}_j, & \quad \text{otherwise} \end{cases}$$
\end{fleqn}

\begin{fleqn}[3em]
\noindent\texttt{With fleqn and optional argument [3em]: }
$$d_j = \begin{cases} \text{newval}_i, & \quad i = j\\ \text{randval}_k, & \quad k = j\\ \text{bestval}_j, & \quad \text{otherwise} \end{cases}$$
\end{fleqn}

\end{document}


• +1. Nice use of the nccmath package! – Mico Apr 29 '17 at 20:04
• Thanks, @Mico. The package has many useful little things – the main point for me being medium-sized maths, intermediate between display style and text style for fractions, integrals, matrices and so on. – Bernard Apr 29 '17 at 20:16