7

I want to write two simple equations one below the other, but it seems that aligned environment aligns to the right and I want to align them to the left. Here is the code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
S_1' (x_0) = S_n' (x_n) = 0 \quad \text{(clamped boundary conditions),} \quad \text{or} \\
S_1'' (x_0) = S_n'' (x_n) = 0 \quad \text{(natural boundary conditions)}
\end{aligned}
\end{equation*}

\end{document}

which produces

enter image description here

but I want S_1''(x_0) to appear directly below S_1'(x_0), not to be moved to the left. Do you please know the solution?

egreg
  • 1,121,712
doremi
  • 187
  • 1
  • 10

3 Answers3

11

The alignment points are marked with an &. If there are several groups (columns of alignments), a further & is used to introduce each new group (except the first group), so that n columns of alignment require 2n-1 ampersands.

Here you can use this code for instance:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*} 
S_1' (x_0) &= S_n' (x_n) = 0 &&\text{(clamped boundary conditions),} \quad \text{or} \\
S_1'' (x_0) &= S_n'' (x_n) = 0 && \text{(natural boundary conditions)}
\end{align*} 

\end{document}

I also suggest these solutions based on alignat*, using the \ArrowBetweenLines command from mathtools (needless to load amsmath in this case), or flalign*:

\documentclass{article}

\usepackage{mathtools}

\begin{document}


\begin{alignat*}{3}
 & & S_1' (x_0) &= S_n' (x_n) = 0 &\quad & \text{(clamped boundary conditions),} \\
\ArrowBetweenLines[\text{or}]%
 & & S_1'' (x_0) &= S_n'' (x_n) = 0 & & \text{(natural boundary conditions)}
 \end{alignat*}

\begin{flalign*} 
& & S_1' (x_0) &= S_n' (x_n) = 0 &&\text{(clamped boundary conditions),} \\
& \text{or} & S_1'' (x_0) &= S_n'' (x_n) = 0 && \text{(natural boundary conditions)} 
\end{flalign*}

\end{document}

enter image description here

Bernard
  • 271,350
9

If you want to left-align the material, you need to provide alignments points via & symbols.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'align*' environment

\begin{document}

\begin{align*}
&S_1' (x_0) = S_n' (x_n) = 0 \quad \text{(clamped boundary conditions), or} \\
&S_1'' (x_0) = S_n'' (x_n) = 0 \quad \text{(natural boundary conditions)}
\end{align*}

\end{document}
Mico
  • 506,678
8

you forgot on anchors for align (ampersands) :

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
S_1' (x_0)  & = S_n' (x_n) = 0 \quad \text{(clamped boundary conditions),} \quad \text{or} \\
S_1'' (x_0) & = S_n'' (x_n) = 0 \quad \text{(natural boundary conditions)}
\end{aligned}
\end{equation*}

\end{document}

enter image description here

Zarko
  • 296,517
  • Thank you all very much! I did not even know there are some anchors for alignment... :-) I am new to Latex. – doremi Jan 02 '18 at 10:14