I have a simple alignment question for Latex tables. At
the moment it looks as follows:
\begin{center}
\begin{tabular}{| c | l | l | }
\hline
\tt {a} & $a = b + c + d + e + f + g + $ \\
& $ e + f + g + h + i + j$ \\ \hline
\end{tabular}
\end{center}
The problem is, that the output looks as follows:
a = b + c + ...
e + f + ....
However, I would like to have it looks as
a = b + c + ...
e + f + ...
Anyone an idea how I could do that in a table?
Thanks,
Klaus
Please use the align environment for multiline equations.
You can add a \phantom{a = } to indicate the should-be-existing spaces.
& $\phantom{a = }e + f + g + h + i + j$ \\ \hline
As KennyTM pointed out, you shouldn't typeset multiline equations using tables like this. But if you must do it, you could do it like this:
\begin{center}
\begin{tabular}{| c | l #{} l | }
\hline
\tt {a} & $a =\;$ & $b + c + d + e + f + g + $ \\
& & $e + f + g + h + i + j$ \\ \hline
\end{tabular}
\end{center}
The usual way is to make an additional column for the a = part; right-aligning it, and removing spacing with the next column for aesthetics:
\begin{tabular}{ c r #{} l } % you have one superfluous l
\tt {a} & $a =$ & $b + c + d + e + f + g +$ \\
& & $e + f + g + h + i + j$ \\
\end{tabular}
Maybe you will need an explicit space after the = sign, so that it's properly spaced with the b.
Another solution would be to have a multiline equation in a single cell of the table, but that amounts to the same (you will need an array environment or something similar to wrap the left part).
Related
I am trying to typeset the following equation in the align-evoirement
\begin{align}
t_2' &= t_2 + \frac{L/C} \\
t_1' &= t_1 + \frac{L + v\Delta t\cos\theta}{c} \\
t_2' - t_1' &= (t_2-t_1) + \frac{L-L-v\Delta t\cos\theta}{C} \\
\Delta t' &= \Delta t - \frac{v\Delta t \cos \theta}{c} \\
\Delta t' &= \Delta t \left(1-\frac{v\cos\theta}{c}\right) \\
\frac{1}{\nu} &= \frac{1}{\nu_0 \sqrt{1-\frac{v^2}{c^2}}}~\left(1-\frac{v\cos \theta {c}\right) \\
\nu &= \nu_0\frac{ \sqrt{1-\dfrac{v^2}{c^2}}}{1-\dfrac{v\cos \theta }{c}}
\end{align}
But when I tried this I got the following message:
[45]
! Missing } inserted.
<inserted text>
}
l.938 \end{align}
?
I copied the equations in Matcha (without the &), where it was perfectly working... I tried some things, but those did not seem to work...
Does anybody know what I did wrong?
At two occasions you write \frac{..} without the mandatary second argument. You must write \frac{...}{...} instead.
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
t_2' &= t_2 + \frac{L}{C} \\
t_1' &= t_1 + \frac{L + v\Delta t\cos\theta}{c} \\
t_2' - t_1' &= (t_2-t_1) + \frac{L-L-v\Delta t\cos\theta}{C} \\
\Delta t' &= \Delta t - \frac{v\Delta t \cos \theta}{c} \\
\Delta t' &= \Delta t \left(1-\frac{v\cos\theta}{c}\right) \\
\frac{1}{\nu} &= \frac{1}{\nu_0 \sqrt{1-\frac{v^2}{c^2}}}~\left(1-\frac{v\cos \theta}{c}\right) \\
\nu &= \nu_0\frac{ \sqrt{1-\dfrac{v^2}{c^2}}}{1-\dfrac{v\cos \theta }{c}}
\end{align}
\end{document}
I am trying to align some fairly long equations the way I would usually do with LaTeX in groff. The general form I am aiming for:
A = B + C
= D * E
+ F * G
= H + I = J
In LaTeX I would do this as follows:
\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
A
& = B + C \\
& =
\begin{aligned}[t]
& D * E \\
& + F * G
\end{aligned} \\
& = H + I
&& = J
\end{alignat*}
\end{document}
In eqn, equation alignment is accomplished with the mark and lineup commands. Quoting Kernighan and Cherry from Typesetting Mathematics 2nd Ed (found here) on how these work:
The word mark may appear once at any place in an equation. It remembers the horizontal position where it appeared. Successive equations can contain one occurence of the word lineup. The place where lineup appears is made to line up with the place marked by the previous mark if at all possible.
Upon reading this I was under the impression that the system does not prohibit both aligning with the previous mark with lineup as well as setting a new mark within the same line of an equation, e.g. I would expect the following:
.PP
.EQ I
A mark =
B + C
.EN
.EQ I
lineup = mark
D * E
.EN
.EQ I
lineup + F * G
.EN
to produce something like this:
A = B + C
= D * E
+ F * G
That is not the case, however. eqn aligns the plus sign with the equals:
A = B + C
= D * E
+ F * G
and produces a warning:
eqn:test.ms:10: multiple marks and lineups
I compile my .ms files with a small script:
eqn $1 -Tpdf | groff -ms -Tpdf > ${1/%.ms/.pdf}
I would like to know if there is some macro that would let me store multiple horizontal offsets (or how to define one). Some clarification as to how exactly mark and lineup macros work would also help.
It is very disappointing that eqn does not allow a new mark to be set. Here is a poor workaround that might be of some use. It consists of repeating the first equation but with the keyword mark in the new position, and diverting the output to nowhere so it does not appear. .di is a base troff to start and end a diversion.
.EQ I
A mark = B + C
.EN
.EQ I
lineup = D * E
.EN
.di mydump
.EQ I
A = mark B + C
.EN
.di
.EQ I
lineup + F * G
.EN
Note, you can also use eqn commands like fwd 99 to move right 99/100 ems, where an em is about the width of the character "m".
Here's a possible solution for having a second mark on the same line as lineup. It uses the base troff sequence \k to mark the current horizontal position into a register myposn. There is then an eqn macro mylineup which calls the eqn special command to run a troff define MyLineup which "returns" a character that has a horizontal movement of myposn units. Before the call eqn sets up some registers with the word following the call, and expects them to be updated to whatever output is desired at that point. We do not use this dummy word, which can be anything, but must not be omitted. For example,
.de MyLineup
. ds 0s "\h'\\n[myposn]u'
. nr 0w \\n[myposn]u
. nr 0h 0
. nr 0d 0
. nr 0skern 0
. nr 0skew 0
..
.EQ I
define mymark '\k[myposn]'
define mylineup 'special MyLineup'
A mark = B + C
.EN
.EQ I
lineup = mymark D * E
.EN
.EQ I
mylineup dummy + F * G
.EN
The lines from .de to .. are the MyLineup definition. The two define lines should be in the first equation. Thereafter, mymark and mylineup dummy can be used in place of mark and lineup. The original mark and lineup are unchanged. If necessary, the real mark can be used again in the line with mylineup, and so on.
To generalise this to having many marks is complicated. The first problem is that mymark is just an eqn define and cannot take a number parameter. It cannot use the special command because it needs to be inline. A trivial solution is just to create a lot of definitions at the start:
define mymark1 '\k[myposn1]'
define mymark2 '\k[myposn2]'
The second problem is that when eqn calls MyLineup it does not pass the following argument ("dummy" which we intend to change to "1") as a parameter of the call, but in the variable 0s; also the string is embedded in formatting code and is actually (in my test anyway) \f[R]\,1\/\fP. So we need to substring the number out of this, with .substring 0s 7 -6. The modified macro and test is:
.\" gets passed 0s = \f[R]\,1\/\fP !!! not just 1
.de MyLineup
. substring 0s 7 -6
. ds 0s \\h'\\n[myposn\\*[0s]]u'
. nr 0w \\n[myposn\\*[0s]]u
. nr 0h 0
. nr 0d 0
. nr 0skern 0
. nr 0skew 0
..
.EQ I
define mymark1 '\k[myposn1]'
define mymark2 '\k[myposn2]'
define mylineup 'special MyLineup'
A mark = B + C
.EN
.EQ I
lineup = mymark1 D * mymark2 E
.EN
.EQ I
mylineup 1 + F * G
.EN
.EQ I
mylineup 2 + X
.EN
.EQ I
lineup = H + I
.EN
I may have been misled by there being several .EQ calls in your example. I was assuming there would be text between the calls and the equations. However, if the intention is to have a single, multi-line equation, it can be done using matrix (or perhaps lpile too). For example,
.nr PS 20p
.nr VS 24p
.PP
.EQ
matrix {
lcol { A }
lcol { = above = above ~ above = }
lcol { B + C above D * E above + F * G above H + I }
lcol { ~ above ~ above ~ above = J }
}
.EN
I am a beginner in latex.I have the following piece of latex code. The code is working fine but I want that all the equality operators of each equation should be aligned. How can it be done?
\begin{enumerate}
\item[Commutative] $a+b = b+a$
\item[Associative] $a+(b+c)=(a+b)+c$
\item[Distributive] $a(b+c)=ab+ac$
\end{enumerate}
I'm unsure if this is possible inside the enumerate environment. An easy alternative is to use a tabular environment instead. In the example below the left and right sides of the equation are contained in two separate columns, with an = appearing between them.
\documentclass[12pt]{article}
\begin{document}
\begin{tabular}{l r#{$=$}l}
Commutative & $a+b$ & $b+a$ \\
Associative & $a+(b+c)$ & $(a+b)+c$ \\
Distributive & $a(b+c)$ & $ab+ac$ \\
\end{tabular}
\end{document}
Using \eqmakebox[<tag>][<align>] (from eqparbox) you can have all elements under the same <tag> be placed in a box of maximum width, together with individual <align>ment as needed. Below I has \eqmakebox[LHS][r] to ensure all elements tagged LHS is right-aligned. The result is alignment around the =.
\documentclass{article}
\usepackage{eqparbox}
\begin{document}
\begin{enumerate}
\item[Commutative] $ a + b = b + a $
\item[Associative] $a + (b + c) = (a + b) + c$
\item[Distributive] $ a(b + c) = ab + ac $
\end{enumerate}
\begin{enumerate}
\item[Commutative] $ \eqmakebox[LHS][r]{$a + b$} = b + a $
\item[Associative] $\eqmakebox[LHS][r]{$a + (b + c)$} = (a + b) + c$
\item[Distributive] $ \eqmakebox[LHS][r]{$a(b + c)$} = ab + ac $
\end{enumerate}
\end{document}
Alternatively you can measure the widest element yourself:
\newlength{\widestelement}
\settowidth{\widestelement}{$a + (b + c)$}
and then use
\begin{enumerate}
\item[Commutative] $ \makebox[\widestelement][r]{$a + b$} = b + a $
\item[Associative] $\makebox[\widestelement][r]{$a + (b + c)$} = (a + b) + c$
\item[Distributive] $ \makebox[\widestelement][r]{$a(b + c)$} = ab + ac $
\end{enumerate}
I am new to R markdown. I have a simple question about how to remove the automated equation numbering in the output PDF. Use the following codes for example:
\begin{align}
\sum_{i = 1}^{n} | (f + g )(x_i) - (f + g)(x_{i-1}) | &= \sum_{i = 1}^{n} | \{ f(x_i) + g(x_i) \} - \{ f(x_{i - 1} + g(x_{i-1}) \} |
\\ &\leq \sum_{i = 1}^{n} | f(x_i) - f(x_{i - 1} | + \sum_{i = 1}^{n} | g(x_i) - g(x_{i - 1})|
\\ &\leq V(f, P) + V(g, P)
\end{align}
It will automatically label the three lines of equations with (1), (2), (3). How do I suppress the numbering?
Thanks for your time!
I was actually looking up how to add numbering... so perfect info swap! Try:
$$
\begin{aligned}
\sum_{i = 1}^{n} | (f + g )(x_i) - (f + g)(x_{i-1}) | &= \sum_{i = 1}^{n} | \{ f(x_i) + g(x_i) \} - \{ f(x_{i - 1} + g(x_{i-1}) \} |
\\ &\leq \sum_{i = 1}^{n} | f(x_i) - f(x_{i - 1} | + \sum_{i = 1}^{n} | g(x_i) - g(x_{i - 1})|
\\ &\leq V(f, P) + V(g, P)
\end{aligned}
$$
This is more of a LaTeX thing than an RMarkdown thing: from my understanding, the $$ $$ isn't numbered, and the aligned environment is intended for use within other environments in order to display a single equation.
So, within the $$ $$ environment, you can use the aligned environment to display an equation, but it won't be numbered.
I missed the response from Werner earlier, but using align* works too. I guess the difference is the nuance in the initial intention.
(Also btw, this means if you use aligned within align, you get a block equation with only one number.)
How could I typeset a formula like this:
It should respect typographic rules, but it must look very similar.
You could use the aligned environment (requires the amsmath package), e.g.
\left. \begin{aligned}
A &= T \\
B &= F
\end{aligned} \right\} \implies A \vee B = T \vee F = T
(Assuming you meant to use logical disjunction and logical implication)
\[
\left.\begin{array}{l}
A = T \\ B = F
\end{array}\right\}
\implies A \lor B = T \lor F = T
\]
This code should do what you want:
\[
\left.
\begin{array}{c}
A = T\\
B = F
\end{array}
\right\}
\Rightarrow A \vee B = T \vee F = T
\]