LaTeX How to Solve Equations and Improve Alignment in Latex Math?

AI Thread Summary
The discussion focuses on improving the formatting of mathematical expressions using LaTeX. A user expresses difficulty in keeping equations aligned and properly formatted. Suggestions include using the align environment to align equations by the equals sign, eliminating unnecessary dollar signs, and utilizing ampersands for alignment control. The importance of consistency in formatting, such as using curly braces around exponents and subscripts, is also emphasized to avoid future errors. Overall, the conversation aims to enhance clarity and presentation in LaTeX typesetting for mathematical equations.
Casio1
Messages
86
Reaction score
0
$y=2x+1$

$y=2x^2+3x+5$

$ a+3b=1$
$2a - b=1$

Multiply through by 3

$6a - 3b = 3$

Subtract equation (3) from (1)

$6a - 3b = 3$
$ a + 3b = 1$
$7a - 0b = 4$

a =$\frac{4}{7}$

Just learning latex on here and trying to understand how I can keep everything in line, which seems difficult with some parts above, is there something I am missing out?

Please advise

Kind regards

Casio
 
Physics news on Phys.org
Casio said:
Just learning latex on here and trying to understand how I can keep everything in line, which seems difficult with some parts above, is there something I am missing out?
What do you mean by difficulties of keeping everything in line? You should include the complete formula between the dollar signs, i.e., write $a=\frac{4}{7}$ instead of a =$\frac{4}{7}$. Also, from the typography viewpoint, it is arguably better to write fractions in inline formulas and in sub- and superscripts using a slash instead of \frac: \(4/7\) instead of \(\frac{4}{7}\). The command \frac is convenient for large display formulas (i.e., formulas that take their own line). However, this remark is probably more appropriate for fine book typesetting rather than online forums.
 
Casio said:
$y=2x+1$

$y=2x^2+3x+5$

$ a+3b=1$
$2a - b=1$

Multiply through by 3

$6a - 3b = 3$

Subtract equation (3) from (1)

$6a - 3b = 3$
$ a + 3b = 1$
$7a - 0b = 4$

a =$\frac{4}{7}$

Just learning latex on here and trying to understand how I can keep everything in line, which seems difficult with some parts above, is there something I am missing out?

Please advise

Kind regards

Casio

To add to Evgeny.Makarov's comments, you can use the align environment (among many, many possibilities in $\LaTeX$) to align equations by the equals sign. For example, the code

Code:
\begin{align*}
a&=x+y\\
b&=x-y
\end{align*}

produces

\begin{align*}
a&=x+y\\
b&=x-y
\end{align*}
 
$\begin{align}r^2=(x + 5)^2 + (y - 3)^2\end{align}$
$\begin{align}r^2=(x - 1)^2 + (y + 1)^2\end{align}$
$\begin{align}r^2=(x - 0)^2 + (y + 2)^2\end{align}$

${2}/{3} + {4}/{6}=$

How is this?

Better
 
Casio said:
$\begin{align}r^2=(x + 5)^2 + (y - 3)^2\end{align}$
$\begin{align}r^2=(x - 1)^2 + (y + 1)^2\end{align}$
$\begin{align}r^2=(x - 0)^2 + (y + 2)^2\end{align}$

${2}/{3} + {4}/{6}=$

How is this?

Better

It is better, but only by accident. There are three things you could do to improve this code.

1. Use only one align environment.
2. Use ampersands to control how things are aligned.
3. Leave off the dollar signs. The align environment is automatically math mode.

For example, suppose you wanted to type these:

Code:
$\begin{align}r^2+x^{2}=(x + 5)^2 + (y - 3)^2\end{align}$
$\begin{align}r^2=(x - 1)^2 + (y + 1)^2\end{align}$
$\begin{align}r^2=(x - 0)^2 + (y + 2)^2\end{align}$

produces

$\begin{align}r^2+x^{2}=(x + 5)^2 + (y - 3)^2\end{align}$
$\begin{align}r^2=(x - 1)^2 + (y + 1)^2\end{align}$
$\begin{align}r^2=(x - 0)^2 + (y + 2)^2\end{align}$

Not aligned the way we want!

Try this code:

Code:
\begin{align}r^2+x^{2}&=(x + 5)^2 + (y - 3)^2\\
r^2&=(x - 1)^2 + (y + 1)^2\\
r^2&=(x - 0)^2 + (y + 2)^2\end{align}

producing

\begin{align}r^2+x^{2}&=(x + 5)^2 + (y - 3)^2\\
r^2&=(x - 1)^2 + (y + 1)^2\\
r^2&=(x - 0)^2 + (y + 2)^2.\end{align}

Much better. Notice the double backslashes at the end of each line marking where the code should begin the next line.

Incidentally: as a defensive $\LaTeX$ programming habit, I always put curly braces around exponents and subscripts, even if it's only one character. That way, if I want to insert another character in the exponent or subscript later, I won't wonder why I get this sort of thing: $x^45$ instead of $x^{45}$.
 

Similar threads

Replies
5
Views
3K
Replies
6
Views
5K
Replies
3
Views
1K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
2
Views
1K
Back
Top