Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am fairly new to TeX and need to create my math assignment with TeX.

I have succeeded aligning all my calculations with the use of \begin{align*} and \intertext{}, however in my document i have sections and subsections and if I \end{align*} and begin after the sections or subsections the alignment is off.

I have gone through google but all I can find is about \begin{equation} and has no mentioning of sections nor graphics.

How do I (if it is possible) make the alignment through the entire document?

Example:

\section{Opgave 1}

\subsection{a) Beregn arealet, der begrænses af kurven for $f(x) = x^{3}$, x-aksen og
linjerne $x = -1$ og $x = 1$.}
\begin{align*} % This
\intertext{Først beregnes det bestemte integrale imellem $x = 0$ og $x = 1$:}
\int_0^1 x^{3}\ dx &= 0.25\\
\intertext{Da den er symetrisk omkring 0 kan vi tage det dobbelte areal:}
0.25 \cdot 2 &= 0.50\\
\end{align*}

\begin{center}
\includegraphics[width=100mm]{opg1graph.png}\\
Opg. 1, a)
\end{center}

\pagebreak

\subsection{b) Bestem arealet af den lukkede figur, der dannes af parablen med regneforskriften $f(x) = -x^2 + 2x + 1$ og den rette linje med regneforskriften $g(x) = -0,5x + 1$}
\begin{align*} % Is not aligned with this
\intertext{Først findes de punkter hvor $g(x)$ afgrænser $f(x)$:}
f(x) &= g(x) \\
-x^2 + 2\cdot x + 1 &= -0.5\cdot x + 1 \\
solve(-x^2 + 2\cdot x + 1 &= -0.5\cdot x + 1,x) \\
x &= 0\\
x &= 2.5\\
\intertext{Så tager vi det bestemte integrale imellem $x = 0$ og $x = 2.5$:}
\int_0^{2.5} -x^2 + 2x + 1\ dx &= 3.54167
\pagebreak
\intertext{Og det bestemte integrale for $g(x)$, for at fjerne arealet under linjen:}
\int_0^{2.5} -0.5\cdot x + 1 dx &= 0.9375
\intertext{Nu trækkes arealet under linjen fra:}
3.54167 - 0.9375 &= 2.60417\\
\end{align*}
share|improve this question
4  
Equation alignment is a local matter, the sizes of the right hand side and left hand side of equations a couple of lines apart (and thus their alignment) normally varies wildly. I haven't felt any urge for this at all, ever. I do use fleqn all the time, I hate centered equations. But that's just me. (Yes, I did write a set of math-heavy lecture notes, and I've read my fill of math books too; it's not just the opinion of a random passerby.) –  vonbrand Apr 5 '13 at 14:49
    
Welcome to TeX.sx! Usually, we don't put 'hello' or 'thank you' in our posts; this isn't perceived as rude, but merely an attempt to keep everything very concise. Now, it may be possible (but horrible practice) to have text interjecting an array environment, but it may not turn out how you like. Margins might die. It bothers the OCD in me too, but I would steer clear of trying to implement this out in the wild. –  Sean Allred Apr 5 '13 at 14:51
    
All right, so it seems I have to stick with aligning sections at a time, a bit of a shame though. Thanks for your answer :-) –  Evilunclebill Apr 5 '13 at 14:51
    
@SvendMortensen Tak :-) I will keep my future examples as minimal as possible. –  Evilunclebill Apr 5 '13 at 14:55
1  
I guess the easiest workaround would be to use fleqn and manually make sure that the left-hand side of each equation has the same width. This could be done with \hrule and \rlap. On the other hand, a likely explanation for why this isn't easy is that it may not be desirable. Having every single equation aligned on its equals sign may imply relations where they don't exist. –  Matthew Leingang Apr 5 '13 at 15:47
add comment

1 Answer

up vote 4 down vote accepted

I agree with the comments to the questions that usually it's not desirable to have one fixed alignment throughout the whole document, but it can be done quite easily:

output

One possibility is to add a suitable \fixedalign command to each align environment you use:

\documentclass{article}
\usepackage{amsmath}
\newcommand\fixedalign{\hspace{0.5\linewidth} &
                       \hspace{0.5\linewidth} \nonumber \\[-\baselineskip]}
\begin{document}
First alignment:
\begin{align*}\fixedalign
a &= b + c
\end{align*}
Second alignment:
\begin{align*}\fixedalign
d + e &= f
\end{align*}
\end{document}

This adds an empty line at the beginning of the alignment that fixes the alignment tab. You can adjust the 0.5\linewidth to your needs, just make sure that the two numbers add up to 1. Note that I added \nonumber so that no additional number is added if the command can be used in align instead of align*.

If you want to define a new environment that adds this empty line automatically, you have to use \NewEnviron from the environ package since align is somewhat special.

\documentclass{article}
\usepackage{amsmath,environ}
\NewEnviron{fixedalign}{%
\begin{align*}
\hspace{0.5\linewidth} & \hspace{0.5\linewidth} \nonumber \\[-\baselineskip]
  \BODY
\end{align*}
}
\begin{document}
First alignment:
\begin{fixedalign}
a &= b + c
\end{fixedalign}
Second alignment:
\begin{fixedalign}
d + e &= f
\end{fixedalign}
\end{document}
share|improve this answer
    
This is awesome, thanks! –  Evilunclebill Apr 6 '13 at 12:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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