How to Solve Equations and Improve Alignment in Latex Math?

Click For Summary
SUMMARY

This discussion focuses on improving equation alignment in LaTeX using the align environment. Users are advised to avoid mixing inline and display math modes, and to utilize ampersands for alignment. The importance of proper syntax, such as omitting dollar signs when using the align environment, is emphasized. Additionally, best practices for writing fractions and managing exponents in LaTeX are highlighted for better typographic results.

PREREQUISITES
  • Basic understanding of LaTeX syntax
  • Familiarity with mathematical environments in LaTeX
  • Knowledge of inline vs. display math modes
  • Experience with LaTeX commands for fractions and alignment
NEXT STEPS
  • Research the LaTeX align environment for multi-line equations
  • Learn about LaTeX best practices for writing fractions
  • Explore LaTeX commands for managing subscripts and superscripts
  • Practice creating complex mathematical documents using LaTeX
USEFUL FOR

Students, educators, and researchers who are learning LaTeX for typesetting mathematical equations and anyone looking to enhance their LaTeX formatting skills.

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 11 ·
Replies
11
Views
8K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
10
Views
3K