2

I have the following code:

\documentclass{article}
\usepackage{amsmath}

\title{latex debugs}
\author{Naitik Mundra}
\date{September 2023}

\begin{document}

\begin{align*}
        & E(a, b)-E\left(a, b^{\prime}\right) \\
        = & \int\left[A(a, \lambda) B(b, \lambda)-A(a, \lambda) B\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda \\
        = & \int\left[A(a, \lambda) B(b, \lambda)-
        A(a, \lambda) B\left(b^{\prime}, \lambda\right) \pm A(a, \lambda) B(b, \lambda) A\left(a^{\prime}, \lambda\right) B\left(b^{\prime}, \lambda\right) \pm A(a, \lambda) B(b, \lambda) A\left(a^{\prime}, \lambda\right) B\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda \\
        = & \int A(a, \lambda) B(b, \lambda)\left[1 \pm A\left(a^{\prime}, \lambda\right) \underline{
            B}\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda - \int A(a, \lambda) B\left(b^{\prime}, \lambda\right)\left[
        1 \pm A\left(a^{\prime}, \lambda\right) B(b, \lambda)\right] \rho(\lambda) d \lambda
\end{align*}

\end{document}

Now, when I run this, I get an equation that spills out of the page(document is set to a4paper): Above Problem

I have tried using multiline* and splitting lines manually using \, but I get an error for undefull hbox or an overfull one with no indication as to where the problem actually lies. While using something like \tiny works, it makes the math unreadable.

How can I fix this(preferably by putting line breaks at the \pm and -) so that the fontsize remains the same?

5
  • 2
    Welcome to tex.sx. This isn't a perfect match, but should give you some ideas about breaking long lines: tex.stackexchange.com/q/179922 Commented Sep 11, 2023 at 19:45
  • Please extend your code fragment to complete small document, which reproduce your problem.
    – Zarko
    Commented Sep 11, 2023 at 20:00
  • @Zarko Added the document class, otherwise unchanged. It still reproduces the issue. Commented Sep 11, 2023 at 20:09
  • @barbarabeeton Sorry, but what exactly does that do? I cannot figure it out. (If it using align, already tried that does not work.) Commented Sep 11, 2023 at 20:10
  • 1
    Do you know breqn.sty? The name stands for "breaking equations". Commented Sep 11, 2023 at 21:47

3 Answers 3

4

I think you need to break up line 3 into three parts and line 4 into two parts. To simplify the aligning of the three parts of the old line 3, I'd embed the material to the right of the integral symbol in its own aligned environment.

Separately, I'd also replace all 11 instances of ^{\prime} with ' and -- since they don't do anything useful -- get rid of all 15 pairs of \left and \right auto-sizing directives. In the code below, I've used \bigl and \bigr directives to increase the sizes of the square brackets.

enter image description here

\documentclass[a4paper]{article}
\usepackage{amsmath} % for 'align*' env. and '\DeclareMathOperator' macro
\DeclareMathOperator{\E}{E} % expectations operator

\begin{document}

\begin{align*}
\E&(a, b)-\E(a, b') \\
&= \int\bigl[A(a,\lambda) B(b,\lambda)-A(a,\lambda) B(b',\lambda)\bigr] 
   \rho(\lambda) \,d\lambda \\
&= \int\bigl[ \begin{aligned}[t]
                &A(a,\lambda) B(b,\lambda)- A(a,\lambda) B(b',\lambda) \\
                &\pm A(a,\lambda) B(b,\lambda) A(a',\lambda) B(b',\lambda) \\
                &\pm A(a,\lambda) B(b,\lambda) A(a',\lambda) B(b',\lambda)\bigr] 
                 \rho(\lambda) \,d\lambda 
              \end{aligned} \\
&= \int A(a,\lambda) B(b,\lambda)\bigl[1 \pm A(a',\lambda) \underline{B}
   (b',\lambda)\bigr] \rho(\lambda) \,d\lambda \\
&\qquad- \smash[t]{\int} A(a,\lambda) B(b',\lambda)\bigl[1 \pm A(a',\lambda) 
   B(b,\lambda)\bigr] \rho(\lambda) \,d\lambda
\end{align*}

\end{document}
1
  • Nice and easy. Never thought about nesting the environments. Cheers. Commented Sep 12, 2023 at 0:24
3

You need to break the long lines, I suggest to use two aligned inner environments. The staggering will tell your readers how to read the formulas.

Avoid ^{\prime} not because it's wrong, but because a simple ' is easier to type and to read in the code.

Also avoid all \left and \right that in your formulas do nothing useful and add unwanted horizontal space.

Note the \diff command that adds the correct spacing in front of the differential and has the additional advantage that if you are forced to use an upright “d” (I fervently hope not), you can simply substitute in the definition of \diff rather than chasing the whole document.

Note the small trick in the last line to get the minus sign aligned with the \pm signs in the lines above.

It's also best not to split before the first equals sign, if space constraints allow.

\documentclass{article}
\usepackage{amsmath}

\title{latex debugs}
\author{Naitik Mundra}
\date{September 2023}

\newcommand{\diff}{\mathop{}\!d}

\begin{document}

\begin{align*}
E(a, b) - E(a, b')
 &= \int \bigl[A(a,\lambda) B(b,\lambda)-A(a,\lambda) B(b',\lambda)\bigr]
         \rho(\lambda) \diff\lambda \\
 &= \int \begin{aligned}[t]
         \bigl[ &A(a,\lambda) B(b,\lambda)-A(a,\lambda) B(b',\lambda) \\
                &\pm A(a,\lambda) B(b,\lambda) A(a',\lambda) B(b',\lambda) \\
                &\pm A(a,\lambda) B(b,\lambda) A(a',\lambda) B(b',\lambda)\bigr]
                \rho(\lambda) \diff\lambda
         \end{aligned} \\
 &= \int \begin{aligned}[t]
         &A(a,\lambda) B(b,\lambda)[1 \pm A(a',\lambda) \underline{B}(b',\lambda)] \rho(\lambda)
         \diff\lambda \\
         &\hphantom{\big[}-
          \int A(a,\lambda) B(b',\lambda)[1 \pm A(a',\lambda) B(b,\lambda)] \rho(\lambda)
                 \diff\lambda
        \end{aligned}
\end{align*}

\end{document}

enter image description here

You may want to use \bigl[ and \bigr] also in the last two lines. Your choice.

You might use \resizebox:

\[
\resizebox{\displaywidth}{!}{$\begin{aligned}
        & E(a, b)-E\left(a, b^{\prime}\right) \\
        = & \int\left[A(a, \lambda) B(b, \lambda)-A(a, \lambda) B\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda \\
        = & \int\left[A(a, \lambda) B(b, \lambda)-
        A(a, \lambda) B\left(b^{\prime}, \lambda\right) \pm A(a, \lambda) B(b, \lambda) A\left(a^{\prime}, \lambda\right) B\left(b^{\prime}, \lambda\right) \pm A(a, \lambda) B(b, \lambda) A\left(a^{\prime}, \lambda\right) B\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda \\
        = & \int A(a, \lambda) B(b, \lambda)\left[1 \pm A\left(a^{\prime}, \lambda\right) \underline{
            B}\left(b^{\prime}, \lambda\right)\right] \rho(\lambda) d \lambda - \int A(a, \lambda) B\left(b^{\prime}, \lambda\right)\left[
        1 \pm A\left(a^{\prime}, \lambda\right) B(b, \lambda)\right] \rho(\lambda) d \lambda
\end{aligned}$}
\]

I used your original code just to make a visual comparison:

enter image description here

Definitely not what anybody wants to see.

2

With use of macro \MoveEqLeft and math environment aligned, both defined in the mathtools package:

\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{mathtools}  % <---


\begin{document}

\begin{align*}
    \MoveEqLeft[3]        % <---
E(a, b)-E(a, b') \\
    = & \int\Bigl[A(a,\lambda) B(b, \lambda) - A(a,\lambda) B(b',\lambda)\Bigr] \rho(\lambda) d\lambda  \\
    = & \begin{multlined}[t]    % <---
        \int\Bigl[A(a,\lambda) B(b, \lambda)-
            A(a,\lambda) B(b',\lambda) \pm {} \\
            A(a,\lambda) B(b,\lambda) A(a',\lambda) B(b',\lambda)\pm A(a,\lambda) B(b, \lambda) A(a', \lambda) B(b',\lambda)\Bigr] \rho(\lambda) d\lambda
        \end{multlined}         \\
    = & \begin{multlined}[t]    % <---
        \int A(a,\lambda) B(b, \lambda)\Bigl[1 \pm A(a', \lambda) \underline{
            B}(b', \lambda)\Bigr] \rho(\lambda) d\lambda - {} \\
        \int A(a,\lambda) B(b', \lambda)
            \Bigl[1 \pm A(a',\lambda) B(b,\lambda)\Bigr] \rho(\lambda) d\lambda
        \end{multlined}
\end{align*}

\end{document}

enter image description here

(red lines indicates page layout)

You must log in to answer this question.

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