How to align equation systems in LaTeX? - latex

I'm new to LaTeX and I'm having issues with aligning this equation system. I'm trying to align it in a way such that the x's, +'s, y's and ='s are all aligned. I don't know if that's possible or not, but I couldn't find help online.
I've tried using \systeme*, this way it aligned the ='s.
\[
\systeme*{ax + by=c,dx^2 + ey^2=f}
\]
My next attempt was to use &, which I've noticed you can only use once to change the alignment.
\[
\systeme*{ax& + by=c,dx&^2 + ey^2=f}
\]
This way it aligned the x's.
Thanks for you help.

You can use the alignat environment from amsmath to align multiple points along the same line. So for instance, with your example, you could use the alignat environment with double ampersands in front of each alignment character:
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{5}
&a && x && + b && y && =c\\
&d && x^2 && + e && y^2 && =f
\end{alignat*}
\end{document}
This produces an aligned result:

Another alternative: the environment array where you can align each column left (l), centered (c) or right (r).
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{llll}
ax & + & by & = c\\
dx^2 & + & ey^2 & = f
\end{array}
\]
\end{document}
Here I aligned all of the four columns to the left ({llll}).

Related

Aligning two equations with a 'multiline' bracket around them to previous equations

I am trying to align a set of solutions of an equation to previous equations at the position of their equal signs. Next to the set equations is a bracket that goes over both lines. The code I already have is equivalent to the following:
\usepackage{amsmath}
\begin{align*}
x^2 & = 1 \\
\Rightarrow \quad \left\{
\begin{array}{r l}
x & = - 1 \\
x & = 1
\end{array}
\right. \\
x & = 1
\end{align*}
Output
Is there or can I set another marker to use for alignment? Are there other equation environments or solutions for the bracket itself that would make this obsolete?
Additionally, is there an option to reduce the space left to the equal signs of the last two equations to 'normal' size (to comparison I copied the last solution inside the normal equation environment)?
Edit: The last problem can be fixed by using aligned instead of array.
Edit 2: Answer provided here!

How to have a normal line of text inside a math environment and align it correctly in LaTeX?

I'm a LaTeX beginner and would like to have two equations aligned on the equals symbol which is working fine so far. Now, between these two equations I need a line of text. But LaTeX interprets this as a math formula since it's showing a (2) right next to it.
I would like to have it as normal text without a (2) aligned on the far left.
I have already tried things like
\begin{flushleft} line of text \end{flushleft}
but it's not working, maybe because I'm using it inside an {align} environment.
Not sure if it's important to mention but I'm using Overleaf (online LaTeX editor).
\begin{align}
\tilde{w}_{ij} &=
\begin{cases}
w_{ij} & \text{mit $P(i)$}\\
0 & \text{sonst}
\end{cases}\\
\text{This text be on the far left}\\
\tilde{w}_{ij} &= w_{ij} * P(i)
\end{align}
produces this ->
This sounds like a job for \intertext from amsmath:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
\tilde{w}_{ij} &=
\begin{cases}
w_{ij} & \text{mit $P(i)$}\\
0 & \text{sonst}
\end{cases}\\
\intertext{This text be on the far left}
\tilde{w}_{ij} &= w_{ij} * P(i)
\end{align}
\end{document}

Box in commutative diagram

In the following commuting diagram, I would like to draw a box containing the bottom triangle defined by nodes D, E and F. Do you know how I could do that?
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
Searching here and there, I put together the following:
\documentclass{article}
\usepackage{amsmath}
%\usepackage{tikz-cd}
\usepackage{tikz}
\usetikzlibrary{cd}
\usetikzlibrary{fit, patterns}
\begin{document}
\[
\tikz[%remember picture,
overlay]{
\filldraw[fill=yellow!50,draw=red!50!yellow] (-.5,-3.2) rectangle (3.8,-.4);
}
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\[3em]
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
It outputs:
I didn't edit any of your code within \[ and \], except for adding [3em] in line 18 for the sake of vertical spacing.
The style (colors, margins) may be changed up to your personal taste!

Latex Long Equations Alignment in single column

I need multiple equations aligned in single column of a two columned document. I have tried a mixture of both align and multiline but it does not work.
\documentclass[12pt,journal,compsoc]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}
\maketitle
\section{Introduction}
\begin{align*}
p(W_{i},T_{n})&=\begin{multline*}
p(W_{i},T_{n})\\+(p(W_{i},T_{n})*k/100)
\end{multline*}\\
p(W_{i},T_{n})&=\begin{multline*}
p(W_{i},T_{n})\\+(p(W_{i},T_{n})*k/100)
\end{multline*}\\
\end{align*}
\end{document}
It gives me the error
Package amsmath Error :\begin{multline*} allowed only in paragraph mode
There's no need for multline here; a regular align will do:
\documentclass[journal,compsoc]{IEEEtran}
\usepackage{amsmath,lipsum}
\begin{document}
\section{Introduction}
\lipsum*[1]
\begin{align*}
p(W_i, T_n) ={}& p(W_i, T_n) \\
& + (p(W_i, T_n) \times k / 100) \\
p(W_i, T_n) ={}& p(W_i, T_n) \\
& + (p(W_i, T_n) \times k / 100)
\end{align*}
\lipsum*[2]
\end{document}
Since you're aligning with a line-break, it's easier to use ={}& as opposed to the traditional &= (which would require additional \phantoms to ensure proper alignment).

How to make an equation span the whole page / line in LaTeX?

I have this equation and it's quite big (basically a FDM one) but it aligns with the text and then continues out on the right side to the nothingness. I've tried stuff like \begin{center} and \hspace*{-2.5cm} but to no avail. I want it to use the whole line not just from the left-margin and out to the right.
How do I do it and do I need to install some special package for it?
I use the \[ instead of the displaymath like this
\[
Equation arrays here
\]
The code
\[
\left(
\begin{array}{cccccc}
-(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots & 0 \\
-\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
0 & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) & 0 & \cdots \\
\vdots & 0 & \ddots & \vdots \\
\vdots & \vdots & \vdots & -\kappa & -(2\kappa+\frac{hV\rho}{2}) & (\frac{hV\rho}{2}-\kappa) \\
0 & \vdots & \vdots & 0 & \kappa - \frac{2h\kappa_{v}}{\kappa}(\frac{hv\rho}{2} - \kappa) & -2\kappa \\
\end{array}
\right)
\left(
\begin{array}{c}
T_{1} \\
T_{2} \\
\vdots \\
T_{n} \\
\end{array}
\right)
=
\left(
\begin{array}{c}
Q(0) + \kappa T_{0} \\
Q(h) \\
Q(2h) \\
\vdots \\
Q((n-1)h) \\
2\frac{\kappa_{v}}{\kappa_{v}}T_{out} \\
\end{array}
\right)
\]
The \[ \] delimiters are intended for single-line equations. In basic LaTeX you can use the eqnarray environment to make a multi-line equations, or you can use the multline environment from the amsmath package. The eqnarray environment lets you use \\ for line breaks but if you want the equation to be numbered, you also need to use the \nonumber command on all lines but one to prevent the numbering of all lines. The multline environment is intended for a single equation so it always produces just one equation number too.
EDIT: This isn't what I would do habitually, but since your equation does seem to fit on a single line, here's the code I've used to get whole-line spanning things:
\newenvironment{widefig}[1][1in]{%
\begin{list}{}{\setlength{\itemindent}{-#1}%
\setlength{\leftmargin}{0pt}%
\setlength{\rightmargin}{0pt}}\item
}{%
\end{list}
}
Like the environment name suggests, I wrote it for figures that are too wide to fit inside the margins, so this allows controlling the left margin and permits a figure to be centered on the whole line.
How I modified your example was to wrap it inside a \begin{widefig}[1.5in]-\end{widefig} pair, added
\relpenalty=10000
\binoppenalty=10000
after the \begin{widefig} line to prohibit line breaking inside the formula, and changed the \[\] into \(\) because the widefig environment only works for inline, not display. You might also need to fiddle a bit with the amount of space given on the \begin line to make the equation properly centered.
I don't believe this is very good typesetting style, though, so you'll want to be very careful about using it, and preferably try to fit things inside the margins. For instance, in this case you could also get rid of a few columns in your first matrix; the usual standard is to have only the first, second, and last, but you probably also want the second-to-last row and column, since the changes in the values for the last row and column is a bit surprising. If you did that, it might fit (but I didn't check).
If you really don't want to break the equation over lines and you don't mind breaking the text width, you could try something like: (untested)
\centerline{$\displaystyle <long equation here>$}
could you add a line-break using \\ ?
Begin centre only aligns things like figures, it won't affect line equations.
You might like to look at the American Mathematical Society guide to their package s
ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
You could use the eqnarray environment to break equations into multiple lines.

Resources