6

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?

  • 1
    You need to put alignment symbols, i.e. &, such that LaTeX knows how you wish to align. – user121799 Jan 1 '18 at 23:41
  • since ypu've said in a comment that you are new to latex, a look at some basic documentation might help. for amsmath (which defines align), type texdoc amsmath at a command line prompt. a lot of other good (many more general) suggestions can be found at What are good learning resources for a LaTeX beginner? – barbara beeton Jan 3 '18 at 0:03
8

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}
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

  • Three separate answers posted within 38 seconds of each other! – Mico Jan 1 '18 at 23:43
  • @Mico: That' s for the New Year :o) – Bernard Jan 1 '18 at 23:54
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.