I am working with Lyx and am trying to fit an equation in my margin as it is getting out side of the margin as can be seen in the below image.

enter image description here

I have tried to use the multiline enviornment but it still did not work. I have also looked at different questions but were not helpful.

Can someone help please?

Below is a screen shot of how I am inputting the formula and what I have used in LYX.

enter image description here

  • You can use align, load package mathtools , split the equation after the = sign and use \MoveEqLeft for the first line. – Bernard Sep 2 '19 at 16:43
  • @Bernard - what do you mean by use MoveEqLeft because when I did it, the equation moved all to the left which is even worse now – Annalise Azzopardi Sep 2 '19 at 16:50
  • It has to be used on a line by line basis, for those which need an emulated indent – Bernard Sep 2 '19 at 16:53
  • Please at least provide the formula code and also the necessary starting \documentclass and ending \end{document}. Although your question is essentially about breaking equation into multiple lines, it is helpful that you provide source code to save others the typing. – Ruixi Zhang Sep 2 '19 at 16:53
  • I'm surprised that the multline environment didn't work. But you said multiline; that's entirely different. – barbara beeton Sep 2 '19 at 19:23

Here two possibilities: one with the aligned environment, nested in equation, ans using\MoveEqLeftfrommathtools, the other usesflalignand an *adhoc* alignment point. Both use the medium-size fractions (\mfrac) fromnccmath`for the numerical fractions, as I think it looks better:




 \MoveEqLeft -\ell (\beta _{0},\boldsymbol{\beta }) + \lambda \|\boldsymbol{\beta }\|_{1} = \\
 & \biggl[-\frac{1}{n}\biggl(\sum_{i = 1}^{n} (\beta _{0}x_{i0} + \mathbf{x}^T\boldsymbol{\beta })y_i-\log(1 + \exp(\beta _{0}x_{i0} + \mathbf{x}^T\boldsymbol{\beta }))\biggr)\biggr] \\
 \text{where} &\phantom{ + } \boldsymbol{\beta } = (\beta _{1},\dots, \beta _{p})^{T}\text{ and } x_{i0} = 1 \text{ for all }i.

Next, we need to show that the negative log-likelihood function is convex. By showing convexity it means that a local minimum exists which is the global minimum…

-\ell (\beta _{0},\boldsymbol{\beta }) & + \lambda \|\boldsymbol{\beta }\|_{1} = \notag \\
 &\phantom{ + } \biggl[-\mfrac{1}{n}\biggl(\sum_{i = 1}^{n} (\beta _{0}x_{i0} + \mathbf{x}^T\boldsymbol{\beta })y_i-\log(1 + \exp(\beta _{0}x_{i0} + \mathbf{x}^T\boldsymbol{\beta }))\biggr)\biggr] \\%
 \text{where} &\phantom{ + } \boldsymbol{\beta } = (\beta _{1},\dots, \beta _{p})^{T}\text{ and } x_{i0} = 1 \text{ for all }i. \notag


enter image description here

| improve this answer | |
  • I would like to thank you for the above however this is still not working. My document class is book (standard class). I don't know if this impacts the whole thing. I will add in my question some screen shots of how the lyx write is being shown – Annalise Azzopardi Sep 3 '19 at 15:21
  • used this link: and seems it is working tex.stackexchange.com/questions/365948/… – Annalise Azzopardi Sep 3 '19 at 15:34
  • What does ‘not working’ mean, exactly? Does the result still overflow in the margin? Whether it is the book or the article class has no importance here. The only problem I can imagine would come from your real margins, which I don't know. – Bernard Sep 3 '19 at 16:23
  • Basically what was happening the formula was still going outside my margins. But I have sorted it usng the AMS Multline Equation – Annalise Azzopardi Sep 3 '19 at 16:28
  • I agree multline should work, but I don't understand why an aligned solution doesn't. – Bernard Sep 3 '19 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.