This is my output:
The problem, of course, is with the misplaced third line. What should happen is this:
- The four left-hand equal signs ought to be aligned;
- additionally minus signs and plus signs from the second and third lines should be aligned, respectively;
- this additional alignment should not affect first or fourth lines.
Here is what I tried (full working example simplified document, so you may copy):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[LGR,T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage[estonian]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[a4paper]{geometry}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage[pdftex]{graphicx}
\newgeometry{margin=2.5cm}
\DeclareSymbolFont{upgreek}{LGR}{cmr}{m}{n}
\DeclareMathSymbol{\ppi}{\mathord}{upgreek}{`p}
\newcommand{\f}[2]{\frac{#1}{#2}}
\newcommand{\Int}[3]{\int\limits_{#1}^{#2}{#3}\, \mathrm{d}x}
\setlength\parindent{0pt}
\begin{document}
\begin{align*}
a_k &= \f{2}{\ppi}\Int{0}{\ppi}{f(x)} = \f{2}{\ppi}\Int{0}{\f{\ppi}{2}}{\left(
\f{\ppi}{2}-x\right)} + \f{2}{\ppi}\Int{\f{\ppi}{2}}{\ppi}{\ppi} = \\
&=\begin{alignedat}[t]{2}
\f{2}{\ppi} \f{\ppi}{2} \left(\f{\ppi}{2}\right)-&
\f{2}{\ppi} \f{1}{2} \left(\f{\ppi}{2}\right)^2 +&
\f{2}{\ppi}\ppi\left(\ppi-\f{\ppi}{2}\right)=\\
&= \f{\ppi}{2} -& \f{\ppi}{4} +& 2\f{\ppi}{2} =
\end{alignedat}\\
&=\f{5}{4}\ppi
\end{align*}
\end{document}
The part that is of interest to this question, of course, is the following subpart of the above:
\begin{document}
\begin{align*}
a_k &= \f{2}{\ppi}\Int{0}{\ppi}{f(x)} = \f{2}{\ppi}\Int{0}{\f{\ppi}{2}}{\left(
\f{\ppi}{2}-x\right)} + \f{2}{\ppi}\Int{\f{\ppi}{2}}{\ppi}{\ppi} = \\
&=\begin{alignedat}[t]{2}
\f{2}{\ppi} \f{\ppi}{2} \left(\f{\ppi}{2}\right)-&
\f{2}{\ppi} \f{1}{2} \left(\f{\ppi}{2}\right)^2 +&
\f{2}{\ppi}\ppi\left(\ppi-\f{\ppi}{2}\right)=\\
&= \f{\ppi}{2} -& \f{\ppi}{4} +& 2\f{\ppi}{2} =
\end{alignedat}\\
&=\f{5}{4}\ppi
\end{align*}
\end{document}
I believe I understand what the problem is. Have a look at the penultimate line inside the alignedat
environment. There I have written &=
; unfortunately, the line break \\
from the line previous only applies to the alignedat
environment. It does not reach the align*
environment.
So ideally this \\
should have a dual role, signalling alignedat
and align*
simultaneously. Simply put, can I do something like this (cf. \insertcommand{}
):
\begin{document}
\begin{align*}
a_k &= \f{2}{\ppi}\Int{0}{\ppi}{f(x)} = \f{2}{\ppi}\Int{0}{\f{\ppi}{2}}{\left(
\f{\ppi}{2}-x\right)} + \f{2}{\ppi}\Int{\f{\ppi}{2}}{\ppi}{\ppi} = \\
&=\begin{alignedat}[t]{2}
\f{2}{\ppi} \f{\ppi}{2} \left(\f{\ppi}{2}\right)-&
\f{2}{\ppi} \f{1}{2} \left(\f{\ppi}{2}\right)^2 +&
\f{2}{\ppi}\ppi\left(\ppi-\f{\ppi}{2}\right)=\\
\insertcommand{\\ &=} \f{\ppi}{2} -& \f{\ppi}{4} +& 2\f{\ppi}{2} =
\end{alignedat}\\
&=\f{5}{4}\ppi
\end{align*}
\end{document}
so that the \\ &=
is sent to align
, and after that, alignedat
continues?
I am very much hoping that such a minor tweak suffices; but other answers are welcome, too (if they do not require (much) manual usage of \!
-s and so on).