0

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

6
  • You can use align, load package mathtools , split the equation after the = sign and use \MoveEqLeft for the first line.
    – Bernard
    Commented Sep 2, 2019 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 Commented Sep 2, 2019 at 16:50
  • It has to be used on a line by line basis, for those which need an emulated indent
    – Bernard
    Commented Sep 2, 2019 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. Commented Sep 2, 2019 at 16:53
  • I'm surprised that the multline environment didn't work. But you said multiline; that's entirely different. Commented Sep 2, 2019 at 19:23

1 Answer 1

1

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:

\documentclass{article}

\usepackage{nccmath}
\usepackage{mathtools}

\begin{document}

\begin{equation}
\label{off-margin}
\begin{aligned}
 \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.
\end{aligned}
\end{equation}

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…

\begin{flalign}
  \label{off-margin1}
-\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
\end{flalign}

\end{document} 

enter image description here

5
  • 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 Commented Sep 3, 2019 at 15:21
  • used this link: and seems it is working tex.stackexchange.com/questions/365948/… Commented Sep 3, 2019 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
    Commented Sep 3, 2019 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 Commented Sep 3, 2019 at 16:28
  • I agree multline should work, but I don't understand why an aligned solution doesn't.
    – Bernard
    Commented Sep 3, 2019 at 16:34

You must log in to answer this question.

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