Typesetting the numbered mathematical formula in latex - latex

How to typeset the following numbered mathematical formula:

Use amsmath's cases environment:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\Delta(x) = \begin{cases}
1 & \text{if $x > 0$} \\
-1 & \text{if $x < 0$} \\
0 & \text{otherwise}
\end{cases}
\]
\end{document}

Here is one way to do it:
$
\Delta(x)=
\left\{
\begin{matrix}
1 & \mathrm{if}~x>0 \\
-1 & \mathrm{if}~x<0 \\
0 & \mathrm{otherwise}
\end{matrix}
\right.
$
Which produces the equation you wanted like this:
The example LaTeX equation
This type of equation has a few key tricks in it:
The left bracket has to be declared as \{ in order for LaTeX to
know to display it since it is a special character
Also, the left brace has to be resized to match however many rows you include in your equation, which is done by the \left command preceding it. This can also be done for (, [, etc.
Since you have a \left command, it has to be accompanied by a \right}, but you don't want to display the right brace, so the \right. ends the section without displaying the right brace.
The \mathrm command turns the text inside it back to normal text (removing the math mode temporarily) so that your "if" and "otherwise" aren't italicized.
The ~ just adds a little space so that your "if" doesn't collide with the x > 0, which often happens when using mathrm
Alternatively, you can check out this post for other ways to write piecewise functions in LaTeX. I hope this helps.

Related

LaTeX align environment missing $ inserted

I'm using an Align environment inside of a proof, and I'm getting the error "Missing $ inserted." I've commenting out all but the first line of the align makes the error go away, but I still can't figure out what the problem is. No solution I could find works. Am I missing something?
\documentclass[12pt,letterpaper]{article}
\usepackage{ifpdf, enumerate}
\usepackage{mla}
\usepackage{gb4e}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{stmaryrd}
\newcommand{\tuple}[1]{\ensuremath{\left \langle #1 \right \rangle }}
\newcommand{\evaluation}[2][]{\ensuremath{\llbracket #2\rrbracket^{#1}}}
\begin{document}
\begin{proof}
\begin{align*}
\evaluation[\mathbb{M}]{(Mx)(D (x) \& V (x))} = 1 \iff \\
\evaluation[\mathbb{M}]{\lbrack \alpha / x \rbrack (D (x) \& V (x))} = 1 \text{for most constants \alpha} \\
\evaluation[\mathbb{M}]{(D (\alpha) \& V (\alpha))} = 1 \text{for most constants \alpha } \\
\evaluation[\mathbb{M}]{D (\alpha)} = 1 \text{and} \evaluation[\mathbb{M}]{V (\alpha)} = 1 \text{for most constants \alpha } \\
F(\alpha) \in F(D) \text{and} F(\alpha) \in F(V) \text{for most constants \alpha } \\
\intertext{Examining the definitions of the model, we see that there are only four entities that are both in $F(D)$ and $F(V)$: Alice, Bob, Colin, and David. Because this is not more than half of the total twelve entities in the universe, our naive definition of ``most'' is not satisfied. Therefore the statement is false, which implies that the truth value of the origenal proposition is not 1.}
\end{align*}
\end{proof}
\end{document}
Here is what the error message looks like.
./test.tex:24: Missing $ inserted.
<inserted text>
$
l.24 \end{align*}
?
You've missed only one tricky fact: \alpha only works in math mode, so if you replace all occurrences of
\text{for most constants \alpha} \\
(lines 18, 19, 20, 21) with
\text{for most constants }\alpha \\
then your tex will compile sweetly. Also:
\text{for most constants}\ \alpha \\
or:
\text{for most constants $\alpha$} \\
as you already did in line 22 of your code (...$F(D)$ and $F(V)$...).
This answer is not applicable to this exact case, but the given error can also pop up if the "amsmath" package is not being used. It becomes tricky because the whole code looks alright except I had forgotten to add the \usepackage{amsmath} line in the beginning of the document.

How to number gathered equations using single number

I want to number gathered equations, but single number for several equations. Following is the code I've used. But it results numbering both equations. I want to equations to be justified, not right aligned. Spilt and align environment right align the equations. Is there any way to do this?
\begin{gather}
\eta_{c1} P_{pv}(k) + \eta_{c2} P_{bat}(k) \leq P_{conG,rate} \\\
P_{grid} + P_{load} \geq -P_{conG,rate}
\end{gather}
After \ you can put \nonumber this way you can avoid having both equations numbered
As said by Good Luck, you can add \nonumber at the end of the line before \\.
A problem I encountered was that when adding a \label{label_name} the Eq.~\ref{label_name} showed as (for example) Eq.2.5 instead of Eq.2. I've managed to sort this by moving the \label{label_name} to the row below \begin{gather}. So for example my code would look like this:
\begin{gather}
\label{labe_name}
e=\sum_{n=0}^{\infty}{\frac{1}{n!}}\\
\begin{aligned}
&\textit{\small Where:}\nonumber\\
&\textit{\small $1^{st}$ line and more explanations to fill the line} \nonumber\\
&\textit{\small $2^{nd}$ line}\nonumber\\
&\textit{\small ext \dots}\nonumber\\
\end{aligned}
\end{gather}
Make sure to have this packages:
\usepackage{amsmath,amssymb}
Here is a cleaner solution than using \nonumber. Using gathered or aligned environments inside an equation environment groups the equations and assigns one number to them. This is recommended by the amsmath user guide.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{gathered}
\eta_{c1} P_{pv}(k) + \eta_{c2} P_{bat}(k) \leq P_{conG,rate}
\\
P_{grid} + P_{load} \geq -P_{conG,rate}
\end{gathered}
\end{equation}
\begin{equation}
\begin{aligned}
\eta_{c1} P_{pv}(k) + \eta_{c2} P_{bat}(k) &\leq P_{conG,rate}
\\
P_{grid} + P_{load} &\geq -P_{conG,rate}
\end{aligned}
\end{equation}
\end{document}

Error while writing multi-valued function in LateX

I am creating a document in LateX and the following multivalued function has been giving me trouble for a while.
The Latex code for the above as I gave is
$\[delta \tau_{i,j}^{k}$ = $\left\{$
\begin{array}{l l}
\frac{1}{L_{k}} & \quad \mbox{if ant k travels on edge \textit{i,j}} \\
0 & \quad \mbox{otherwise}
\end{array} \right. \]
While compiling it gives me the following error
! LaTeX Error: Bad math environment delimiter.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.52 $\[
delta \tau_{i,j}^{k}$ = $\left\{$
?
Any help on fixing this error would be much appreciated.
aschepler is right--it's the [ inside the $.
You may also want to consider the cases environment, which I think is easier for this sort of thing. For you example, you'd have:
\[
\Delta\tau_{i,j}^k=
\begin{cases}
1/L_k & \text{if ant $k$ travels along edge $i,j$} \\
0 & \text{otherwise}
\end{cases}
\]
You can't use both $ $ and \[ \] like that. $ is for in-line equations (fit within a paragraph of text), so you should probably use just \[ \] around your equation and remove all the $s.

Two statements next to curly brace in an equation

How can I write an equation with one curly brace ({), and on the right-hand side next to the curly, two statements in two different lines?
You can try the cases env in amsmath.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
f(x)=\begin{cases}
1, & \text{if $x<0$}.\\
0, & \text{otherwise}.
\end{cases}
\end{equation}
\end{document}
That can be achieve in plain LaTeX without any specific package.
\documentclass{article}
\begin{document}
This is your only binary choices
\begin{math}
\left\{
\begin{array}{l}
0\\
1
\end{array}
\right.
\end{math}
\end{document}
This code produces something which looks what you seems to need.
The same example as in the #Tombart can be obtained with similar code.
\documentclass{article}
\begin{document}
\begin{math}
f(x)=\left\{
\begin{array}{ll}
1, & \mbox{if $x<0$}.\\
0, & \mbox{otherwise}.
\end{array}
\right.
\end{math}
\end{document}
This code produces very similar results.
Are you looking for
\begin{cases}
math text
\end{cases}
It wasn't very clear from the description. But may be this is what you are looking for http://en.wikipedia.org/wiki/Help:Displaying_a_formula#Continuation_and_cases
To answer also to the comment by #MLT, there is an alternative to the standard cases environment, not too sophisticated really, with both lines numbered. This code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{numcases}{f(x)=}
1, & if $x<0$\\
0, & otherwise
\end{numcases}
\end{document}
produces
Notice that here, math must be delimited by \(...\) or $...$, at least on the right of & in each line (reference).
Or this:
f(x)=\begin{cases}
0, & -\pi\leqslant x <0\\
\pi, & 0 \leqslant x \leqslant +\pi
\end{cases}
Here is a way to manually control the size of brace, if cases or \left\{ doesn't provide suitable brace size you want.
\begin{math}
\biggl\{
\begin{array}{l}
statement1\\
statement2
\end{array}
\end{math}
You can choose among \bigl\{ \Bigl\{ \biggl\{ \Biggl\{ to adjust brace size from the smallest to the largest.
Image of different braces
From left to right: cases \left\{ biggl\{ Bigl\{

Collapsible minibox environment in LaTeX

I'm trying to learn LaTeX, currently because otherwise, my professors will be nearly unable to read my homework assignments. I've come across something I want to do, but don't seem to be able to, ie. I have searched google (possibly with a poor keyword set) and not found a solution.
The specific case is as follows: I want to put an ams flalign environment inside a box and have multiple such environments side by side. I have achieved this using minipage, but minipage asks for a width. I would like to use the smallest width in which the flalign environment fits. I realize that I can set the width to 0pt, but I can't help wondering if there's something that is intended to do this.
Also, should I be using minipage? Is there another command I don't know?
Thanks for your reply.
EDIT:
An attempted clarification as to what I want to do. I want equations which are standard, known, given, etc. and short on the left. To the right of those, I want relevant derived equations (and maybe their derivations. Further right, I want actual calculations plugged in.
I feel like what I want is a tabular environment with 3 columns, but I don't think I can put an equation environment in a tabular environment.
This looks like what I want when I render it.
\begin{minipage}[t]{0pt}
\begin{flalign*}
\sigma & = F / A&\\
A & = \pi \left(d/2\right)^2&\\
\epsilon &= \frac{\sigma}{E}&\\
\epsilon_{trans} &= - \nu \epsilon_{longi}& \\
\epsilon &= \frac{\Delta l}{l}&\\
l &= \left( \epsilon + 1 \right) \times l_0&
\end{flalign*}
\end{minipage}
\hspace*{0pt}
\begin{minipage}[t]{0pt}
\begin{flalign*}
d & = \unit[1.8]{mm} = \unit[1.8\e{-3}]{m} &\\
F_T & = \unit[1300]{N}&\\
E_{\text{stainless steel}}&=\unit[193\e9]{Pa}&\\
l_0 & = \unit[.2530]{m}&\\
\nu & = .33&\\
\sigma &= \frac{\unit[1300]{N}}{\pi \times \unit[3.24\e{-6}]{m^2}}&&= \boxed{\unit[127.7\e6]{Pa}}\\
&&&=\boxed{\unit[18,524]{psi}}\\
\epsilon &= \frac{\unit[127.7\e6]{Pa}}{\unit[193\e9]{Pa}} &&= \boxed{6.6\e{-2}}\\
\epsilon_{trans} &= -.33 \times 6.6\e{-2} &&=\boxed{-2.2\e{-2}}\\
l &= \left( 6.6\e{-2} + 1 \right) \times \unit[.2530]{m} &&= \boxed{\unit[.2797]{m}}
\end{flalign*}
\end{minipage}
I'm not sure exactly what you're trying to achieve, but amsmath's align* environment might do what you want (without resorting to minipages):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x&=y & X&=Y & a&=b+c & mn&=ab\\
x’&=y’ & X’&=Y’ & a’&=b & m'n'&=a'b'\\
x+x’&=y+y’ & X+X’&=Y+Y’ & a’b&=c’b & m'&=a'
\end{align*}
\end{document}
As to your minipage question: it requires a width because TeX needs to know where to break the lines. If you don't want the line-breaking algorithm to be used, you probably don't want a minipage.
Edit:
If you want multiple columns and don't care about the vertical alignment of material across the columns, that can be obtained easily enough with the multicols package:
\documentclass{article}
\usepackage{multicols}
\usepackage{lipsum}% just for some example text
\begin{document}
% The * version allows the columns to have ragged bottoms.
% The argument 2 is the number of columns.
\begin{multicols*}{2}
\lipsum[1]% one paragraph of Lorem ipsum.. filler text
\vfil% fills the remainder of the column with white space
\columnbreak% force a column break
\lipsum[2]% another paragraph of text
\vfil% fills the remainder of the column with white space
\end{multicols*}
\end{document}
You might find something to help you in the empheq and mathtools packages. empheq allows you to box equations and mathtools should provide some useful environments for stacking them horizontally.

Resources