2

Edited

I am having trouble using the alignenvironment, which I've read is a better alternative to eqnarrayto align equations.

Hereafter I display the PDF output of my Latex code:

Output

I would like the max to be aligned with the \forall:

enter image description here

The code that I've written is the following:

\begin{align*}
\max_{\lambda,\lambda_0} M
\\
\forall i \in \{1,...,n\}, &\; \frac{y_i f(\mathbf{x}_i)}{\|\vec{\lambda}\|} \geq M 
\\
&\; \Leftrightarrow y_i \left(\frac{\vec{\lambda}^{\:T} \mathbf{x}_i+\lambda_0}{\|\vec{\lambda}\|}\right) \geq M 
\end{align*}

Would someone kindly point out what am I getting wrong?

3
  • Welcome to TeX.SX! Please don't post code as pictures, it's really annoying for those that might want to test the code. Copy the code into the question. May 4, 2016 at 13:40
  • Do you mean vertically aligned?
    – Bernard
    May 4, 2016 at 13:45
  • Indeed, vertically aligned. May 4, 2016 at 13:47

2 Answers 2

3

The following solution nests an aligned environment inside an align* environment.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
&\max_{\lambda,\lambda_0} M\\
&\,\forall i \in \{1,\dots,n\}, 
  \begin{aligned}[t]
    &\frac{y_i f(\mathbf{x}_i)} {\|\vec{\lambda}\|} \geq M \\
    &\Leftrightarrow y_i \biggl(\frac{\vec{\lambda}^{\:T} 
        \mathbf{x}_i+\lambda_0}{\|\vec{\lambda}\|}\biggr) \geq M
  \end{aligned}
\end{align*}
\end{document}
3
  • The issue with this solution is that the first fraction is no longer aligned with the \Leftrightarrow. I would like two vertical alignments: 1) \max aligned with \forall and 2) the first fraction aligned with \Leftrightarrow. May 4, 2016 at 14:03
  • Ok the edited version also works, thank you. May 4, 2016 at 14:09
  • @DaneelOlivaw - When I posted the first version of my answer, I hadn't noticed yet that you'd edited your posting in the meantime. Once I saw the new version, I updated my answer accordingly...
    – Mico
    May 4, 2016 at 14:17
3

Maybe this is the desired output:

documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{alignat*}{2}
&\! % or \max would be a bit to the right
\max_{\lambda,\lambda_0} M
\\
&\forall i \in \{1,\dots,n\},
&&\frac{y_i f(\mathbf{x}_i)}{\|\vec{\lambda}\|} \geq M
\\
&& \Leftrightarrow {} &
  y_i \left(\frac{\vec{\lambda}^{\,T}
  \mathbf{x}_i+\lambda_0}{\|\vec{\lambda}\|}\right) \geq M
\end{alignat*}

\end{document}

enter image description here

2
  • Ok yes, this is what I was looking for - just changing places of the third & and \Leftrightarrow. Thank you. By the way, what is the purpose of the empty brackets situated at the right of \Leftrightarrow? May 4, 2016 at 14:07
  • @DaneelOlivaw Spacing.
    – egreg
    May 4, 2016 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .