1

I'm using the breqn package for the first time, and while in one equation I get, using

\begin{dmath*}
\sum_{k=0}^{n} \left(\frac{k}{n} - x\right)^2 \binom{n}{k} x^k (1 - x)^{n - k}  
= \left(1 - \frac{1}{n}\right)x^2 + \frac{1}{n}x - 2x^2 + x^2 
= \frac{1}{n}x(1 - x) 
\leq \frac{1}{4n}\ ,
\end{dmath*}

something like that

enter image description here

I get just in the next line, something like that

\begin{dmath*}
\sum_{k \in F}\binom{n}{k}x^k(1 - x)^{n -k} 
\leq \frac{1}{\delta^2}\sum_{k \in F} \left(\frac{k}{n} - x\right)^2
\binom{n}{k}x^k (1 - x)^{n -k}
\leq \frac{1}{\delta^2}\sum_{k = 0}^{n} \left(\frac{k}{n} - x\right)^2
\binom{n}{k}x^k (1- x^k)
\leq\frac{1}{4n\delta^2} \ ,
\end{dmath*}

enter image description here

which is basically the same code but looks way better than the first equation. So I wonder if there's a way to adjust the dmath enviroment to make the first equality on the first equation go to the first line, and then break on the second, making my first equation have only three lines.

egreg
  • 1,121,712
  • You should use k\hiderel{=}0 and k\hiderel{\in}F in order to avoid the bad spacing, but this is a detail. Apparently according to its heuristics, breqn decides that making a single line with the first = sign yields too long a line and so breaks it. Avoid breqn if you want quality output: some more work will be required, but it will be rewarding. Otherwise, be happy with what you get. – egreg Jul 24 '18 at 22:39
  • Actually breqn worked better for me than split, for example, which is a mess, up to this point. It seems that it's just a limitation and that I should work case by case when using it to decide which is better. – 園田海未 Jul 24 '18 at 22:48

2 Answers2

1

You can force breqn to use a specific layout for your equation. Unfortunately there seems to be a bug in the package because the example fails if I comment in the last line (regardless of which relational symbol I use). So, yeah, just don't use breqn.

\documentclass{article}
\usepackage{breqn}
\begin{document}
\begin{dmath*}[layout={L}]
\sum_{k\hiderel{=}0}^{n} \left(\frac{k}{n} - x\right)^2 \binom{n}{k} x^k (1 - x)^{n - k}  
= \left(1 - \frac{1}{n}\right)x^2 + \frac{1}{n}x - 2x^2 + x^2 
= \frac{1}{n}x(1 - x)
%\leq \frac{1}{4n}
\end{dmath*}
\end{document}

enter image description here

Henri Menke
  • 109,596
0

Seeing as you want to specify where to break the lines, you might as well use align here.

Unrelated to the main question, but, it looks like you are trying to add some space before the comma? If that's the case, I'd recommend using \, to add some unbreakable thinspace before the comma.

enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
\sum_{k=0}^{n} \left(\frac{k}{n} - x\right)^2 \binom{n}{k} x^k (1 - x)^{n - k}  &= \left(1 - \frac{1}{n}\right)x^2 + \frac{1}{n}x - 2x^2 + x^2\\
&= \frac{1}{n}x(1 - x)\\
&\leq \frac{1}{4n}\,,
\end{align*}

\end{document}

Similarly, for your 2nd equation you could use this code.

enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
\sum_{k \in F}\binom{n}{k}x^k(1 - x)^{n -k} &\leq \frac{1}{\delta^2}\sum_{k \in F} \left(\frac{k}{n} - x\right)^2 \binom{n}{k}x^k (1 - x)^{n -k} \\
&\leq \frac{1}{\delta^2}\sum_{k = 0}^{n} \left(\frac{k}{n} - x\right)^2 \binom{n}{k}x^k (1- x^k)\\
&\leq\frac{1}{4n\delta^2},
\end{align*}

\end{document}
Milo
  • 9,440
  • Is it a limitation of breqn? Did it decided that the first equality was too long and there was nothing I could do about it? – 園田海未 Jul 24 '18 at 22:47
  • I'm no expert on the pros and cons of breqn, but one can typeset most equations well, if not better, without needing breqn. I suggest reading up on the different ways of aligning equations using amsmath, e.g. multline, align, gather etc. I've loaded the mathtools package here which is based on amsmath and includes a number of up-to-date fixes. – Milo Jul 24 '18 at 22:54
  • By the way, I can't fully tell but are you trying to add some space between the end of your equation and the comma? If so, I'd recommend writing \,,. The command \, makes some unbreakable thinspace. – Milo Jul 24 '18 at 22:56