I have been using common align environment from amsmath and noticed strange behaviour of kerning when placing the & sign from either side of the + sign. Namely assume the following code and the result it produces for me:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a&+b\\
a+&b
\end{align}
\end{document}
Is this a bug? If this is intended behaviour, can you please explain why the kerning is different in those cases?
For all it could matter I am using TexStudio 4.0.1 and MikTex (Console version 4.8, all packages updated on 24th Aug 22) to produce the output from the code.
I think it's working as expected. The ampersand characters defines a boundary between left and right columns, which in turn are right and left aligned, respectively. Everything to the left is pushed leftwards and everything to the right is pushed rightwards.
Consider the code
\documentclass{article}
\usepackage{amsmath}
\setlength\fboxsep{0pt}
\begin{document}
\begin{align}
\boxed{a} \clap{\rule[-3pt]{0.4pt}{12pt}}& + b\\
a + \clap{\rule[-3pt]{0.4pt}{12pt}}& \boxed{b}
\end{align}
\end{document}
IMO there's the perfect split between two columns. The extra spacing comes from + being an operator so LaTeX does add extra spacing around it.
In your code, there is another issue. An ampersand placed at the right of an operator cancels its status of being the operator. The effect is it's losing expected spacing; the same would happen with =. Adding anything between an operator and & restore its status. Therefore, {} placed right before & is he easiest solution
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a & + b \\
a + {}& b
\end{align}
\end{document}
Related
I have the following problem
\usepackage[fleqn]{amsmath}
\begin{equation}
\begin{split}
\min Y\\
\textrm{s.t.}
\end{split}
\end{equation}
\begin{align}
a+b=145641574\\
c+d<e
\end{align}
creates the following output:
So far so good. The formulas are essentially left-aligned. The numbering is right-aligned. But within the formulas, splits or line breaks result in right alignment. These should also be left-aligned.
Thanks in advance and have a nice weekend!
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}
I want to do the task - addition to the column with unknown digits.
How to make everything so that it is aligned in the center of the boxes and digits?
To digits were under the digits, boxes under the digits, digits under the boxes?
\def\msquare{\mathord{\scalerel*{\Box}{gX}}}
\begin{multline*}
\begin{array}{r}
+
\begin{array}{r}
\msquare64\msquare\msquare\msquare\\
661977\\
\end{array}\\
\hline
\begin{array}{r}
1\msquare\msquare631\msquare
\end{array}\\
\end{array}
\end{multline*}
This can be done with an array. As your values are just squares or number, it is better to use the tabular environment where intercolumn spacing can be more finely controlled. To do that, the simpler is to redefine the tabcolsep length, but there packages like array that can provide other means to control it.
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
% \def\msquare{\mathord{\scalerel*{\Box}{gX}}} % redifined, because I do know what \Box does.
\def\msquare{\raisebox{1mm}{\framebox[2mm][r]{}}}
\setlength{\tabcolsep}{0.5pt}
\begin{multline*}
\begin{array}{r}
+
\begin{tabular}{ccccccc}
&\msquare&6&4&\msquare&\msquare&\msquare\\
&6&6&1&9&7&7\\
\hline
1&\msquare&\msquare&6&3&1&\msquare
\end{tabular}\\
\end{array}
\end{multline*}
\end{document}
To avoid the redefinition of tabcolsep in all your document, enclose this code in braces.
Im trying to add a dot like • for a dot product but it always ends up acting like a bullet point creating a new line. I've tried \cdot and \bullet. I think its being treated as a bullet because I'm doing it inside an itemized list. Is there a way to make it just as a dot?
Have you tried :
$\bullet$
Try \cdot in math mode. It is a good way to indicate multiplication:
\documentclass{article}
\begin{document}
Here is a product: $a \cdot b$.
\end{document}
Note that the dollar symbol represents the math mode.
just had the same problem...
Math mode $...$ is not essential for this:
\documentclass{minimal}
\begin{document}
\noindent
Here's an example with $\bullet$ math mode
\newline
And here one in \textbullet text only
\newline
Although you may want to give the last \textbullet \ more spacing
\end{document}
giving:
Is it possible to get multline like behavior within a gather
environment? I have a set of equations in a gather environment, but
one of them is too long, and I'd like to split it up onto two lines
where the first line is left-aligned and the second line is right-aligned
(just like multline). If there is a way of aligning individual lines
within the gather or split environment (like flushleft or flushright but
functional in mathmode) this would solve the problem.
The mathtools package has an inner multlined environment similar to gathered and the likes, but it required a small amount of manual tweaking:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
% \begin{multline}
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut} \\
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut}
% \end{multline}
\begin{gather}
\framebox[0.8\linewidth]{\strut} \\
\begin{multlined}[b][\linewidth-3\multlinegap]
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut} \\
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut}
\end{multlined} \\
\framebox[0.4\linewidth]{\strut}
\end{gather}
\end{document}
I haven't tested this, but you can try putting \hfill in front of the second line.
Having said that: IMHO, multline behavior inside a gather environment is undesirable. Especially if you have the fleqn option enabled, you should consider the following option:
put the long equation inside a split, with alignment on the left side of the equality. Assuming the right hand side is too long, put its second part on a new line (still inside the split) and use \hspace{1cm} (or some other length) to indent the second part a bit further.
For an overview of all AMS multiline blocks, see the amsmath documentation.