Math & Sciencelong inline equation does not break

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
QwareeqMathematics
Posts: 68
Joined: Mon Jul 06, 2009 7:44 pm

long inline equation does not break

Post by QwareeqMathematics »

Hi,

I'm facing a problem in long inline equation .

here is a simple example ;

Code: Select all

\documentclass{article}
\usepackage{amssymb,amsmath}

\begin{document}
Let $T$ be a caterpillar with diameter $d$. Then $V(T)= \left\{ x_r: r = 1, 2,\ldots , d –1,\ {and}\ deg(x_r)> 1\right\} \cup \left\{ x_{ri} : i = 1, 2, \ldots, t_r, r = 1, 2,\ldots, d –1, \ {and}\ deg(x_{ri}) =1 \right\}$. The number of vertices of $T$ is $n = d –1  + \sum\limits_{r=1}^{d-1}t_r$.  Observe that, $x_{ri}$ is adjacent to $x_r$, and $x_r$  is adjacent to $x_{r+1}$, for $r = 1, 2,\ldots, d-2$. Note that, the caterpillar graph is represented in Figure 1.
 
\end{document}

how to break that equation to be in the same paragraph width ? Is there any way to make that for entire document at once?

Also, I tried to put in $$ ...$$ tags, the same problem , it extended to the margin...

Best regards

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10359
Joined: Mon Mar 10, 2008 9:44 pm

long inline equation does not break

Post by Stefan Kottwitz »

Have a look at this topic from today: Equation crosses the right boundary

Wide equations should be in displayed mode, similar to what you did with $$. But don't use this TeX syntax with LaTeX, use \[ ... \] otherwise the spacing could be incorrect.

But for multi-line equations use multline, gather, align or another such environment of amsmath.

Stefan
LaTeX.org admin
QwareeqMathematics
Posts: 68
Joined: Mon Jul 06, 2009 7:44 pm

long inline equation does not break

Post by QwareeqMathematics »

Thank you,

I tried the \[...\] , the same problem , the equation crosses the right boundary. Also, I tried \allowbreak with $...$ and \[...\]. But, I got nothing also.

How could I write it as in-line equation , that it breaks when it reaches the right boundary.

Code: Select all

\documentclass{article}
\usepackage{amssymb,amsmath}

\begin{document}
Let $T$ be a caterpillar with diameter $d$. Then 
\[ V(T)= \left\{ x_r: r = 1, 2,\ldots , d –1,\ {and}\ deg(x_r)> 1\right\} \cup \left\{ x_{ri} : i = 1, 2, \ldots, t_r, r = 1, 2,\ldots, d –1, \ {and}\ \allowbreak deg(x_{ri}) =1 \right\}\] 

The number of vertices of $T$ is $n = d –1  + \sum\limits_{r=1}^{d-1}t_r$.  Observe that, $x_{ri}$ is adjacent to $x_r$, and $x_r$  is adjacent to $x_{r+1}$, for $r = 1, 2,\ldots, d-2$. Note that, the caterpillar graph is represented in Figure 1.
 
\end{document}
Thank you.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

long inline equation does not break

Post by localghost »

Try something like this.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}    % loads »amsmath«
\usepackage{amssymb}

\begin{document}
  Let $T$ be a caterpillar with diameter $d$. Then
  \begin{align*}
     V(T) &= \{ x_r: r = 1, 2,\ldots , d –1,\ \text{and}\ \deg(x_r)> 1 \} \\
          &\mathrel{\phantom{=}}\cup \{ x_{ri} : i = 1, 2, \ldots, t_r, r = 1, 2,\ldots, d –1, \text{and}\ \deg(x_{ri}) =1 \}
  \end{align*}

  The number of vertices of $T$ is $n = d –1  + \sum\limits_{r=1}^{d-1}t_r$.  Observe that, $x_{ri}$ is adjacent to $x_r$, and $x_r$  is adjacent to $x_{r+1}$, for $r = 1, 2,\ldots, d-2$. Note that, the caterpillar graph is represented in Figure 1.
\end{document}
Further reading:
QwareeqMathematics
Posts: 68
Joined: Mon Jul 06, 2009 7:44 pm

long inline equation does not break

Post by QwareeqMathematics »

This is so nice, thank you.

I'm just curious is there any way to break any equation at any point I like ?

I'm going to read that file.


Aha, in Section 2.6 (p. 11) in that document it says this.
»[url=http://ctan.org/pkg/voss-mathmode]Math mode[/url]« document (p. 11) wrote:LaTeX can break an in-line formula only when a relation symbol (=,<,>, …) or a binary operation symbol (+, , …) exists and at least one of these symbols appears at the outer level of a formula. Thus $a+b+c$ can be broken across lines, but ${a+b+c}$ not.
thx
User avatar
Stefan Kottwitz
Site Admin
Posts: 10359
Joined: Mon Mar 10, 2008 9:44 pm

long inline equation does not break

Post by Stefan Kottwitz »

QwareeqMathematics wrote:Aha, in Section 2.6 (p. 11) in that document it says this.
I said it in similar words in the other thread I linked above.
QwareeqMathematics wrote:I'm just curious is there any way to break any equation at any point I like ?
You could use \allowbreak. In your case the problem is that you use \left and \right which need to be on the same line. If you use \big instead, for example, \allowbreak works. Have a look:

Code: Select all

\documentclass{article}
\usepackage{amssymb,amsmath}
\begin{document}
Let $T$ be a caterpillar with diameter $d$. Then
$V(T)= \big\{ x_r: r = 1, 2,\ldots , d –1,\allowbreak\text{ and }
\deg(x_r)> 1\big\} \cup \left\{ x_{ri} : i = 1, 2, \ldots, t_r,
r = 1, 2,\ldots, d –1, \text{ and }\deg(x_{ri}) =1 \right\}$.

The number of vertices of $T$ is $n = d –1  + \sum\limits_{r=1}^{d-1}t_r$. 
Observe that, $x_{ri}$ is adjacent to $x_r$, and $x_r$  is adjacent to
$x_{r+1}$, for $r = 1, 2,\ldots, d-2$. Note that, the caterpillar graph
is represented in Figure 1.
\end{document}
example.png
example.png (22.39 KiB) Viewed 48814 times
Note, I wrote \text{ and } to get this word in text font, and \deg to get the math operator in upright letters, as it's commonly written to distinguish from variables.

Stefan
LaTeX.org admin
QwareeqMathematics
Posts: 68
Joined: Mon Jul 06, 2009 7:44 pm

Re: long inline equation does not break

Post by QwareeqMathematics »

thank you ...
Post Reply