Problem with amsmath's gather environment

I have a lot of math to write so I tried to use align inside gather. When the column was over I was getting badboxes. So I used two gather environments and the output is weird. What is happening and why? How can I fix that?

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\usepackage[utf8]{inputenc}

\setlength{\parindent}{0cm}

\usepackage{setspace}

\usepackage{xltxtra}
\usepackage{xgreek}
\setmainfont[Mapping=tex-text]{GFSDidot.otf}
\setsansfont[Mapping=tex-text]{GFSDidot.otf}

\usepackage[fleqn]{amsmath}
\usepackage{unicode-math}

\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}

\begin{document}

\begin{multicols*}{2}

\begin{gather*}
\begin{aligned}
&\text{70}\\
&e^{jz}=\cos z+j\sin z\\
&\cos z=(1/2)(2\cos z)=\\
&=(1/2)(2\cos z+j\sin z-j\sin z)=\\
&=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
&=(1/2)(e^{jz}+e^{-jz})
\end{aligned}\\
\begin{aligned}
&\text{207}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\phi(t)=K_{p}m(t)\\
&x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\frac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
&\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
&x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
&\cos(a+b)=\cos a \cos b-\sin a \sin b\\
&\phi(t)=K_{p}m(t)\\
&\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
\end{aligned}\\
\begin{aligned}
&\text{265}\\
&g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
&j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
&\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
&=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
\end{aligned}
\end{gather*}

\end{multicols*}

\end{document}

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\usepackage[utf8]{inputenc}

\setlength{\parindent}{0cm}

\usepackage{setspace}

\usepackage{xltxtra}
\usepackage{xgreek}
\setmainfont[Mapping=tex-text]{GFSDidot.otf}
\setsansfont[Mapping=tex-text]{GFSDidot.otf}

\usepackage[fleqn]{amsmath}
\usepackage{unicode-math}

\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}

\begin{document}

\begin{multicols*}{2}

\begin{gather*}
\begin{aligned}
&\text{70}\\
&e^{jz}=\cos z+j\sin z\\
&\cos z=(1/2)(2\cos z)=\\
&=(1/2)(2\cos z+j\sin z-j\sin z)=\\
&=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
&=(1/2)(e^{jz}+e^{-jz})
\end{aligned}\\
\begin{aligned}
&\text{207}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\phi(t)=K_{p}m(t)\\
&x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\frac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
&\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
&x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
&\cos(a+b)=\cos a \cos b-\sin a \sin b\\
&\phi(t)=K_{p}m(t)\\
&\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
\end{aligned}\\
\end{gather*}
\begin{gather*}
\begin{aligned}
&\text{265}\\
&g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
&j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
&\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
&=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
\end{aligned}
\end{gather*}

\end{multicols*}

\end{document}

Edit I:

This is the output with \raggedcolumns as proposed in the comments and obviously there are problems concerning the space left in the first column and the height difference between the first and the second column. Also I don't understand why is there a problem in the first place with gather environments.

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\usepackage[utf8]{inputenc}

\setlength{\parindent}{0cm}

\usepackage{setspace}

\usepackage{xltxtra}
\usepackage{xgreek}
\setmainfont[Mapping=tex-text]{GFSDidot.otf}
\setsansfont[Mapping=tex-text]{GFSDidot.otf}

\usepackage[fleqn]{amsmath}
\usepackage{unicode-math}

\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}

\begin{document}
\raggedcolumns

\begin{multicols*}{2}

\begin{gather*}
\begin{aligned}
&\text{70}\\
&e^{jz}=\cos z+j\sin z\\
&\cos z=(1/2)(2\cos z)=\\
&=(1/2)(2\cos z+j\sin z-j\sin z)=\\
&=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
&=(1/2)(e^{jz}+e^{-jz})
\end{aligned}\\
\begin{aligned}
&\text{207}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\phi(t)=K_{p}m(t)\\
&x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\frac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
&\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
&x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
&\cos(a+b)=\cos a \cos b-\sin a \sin b\\
&\phi(t)=K_{p}m(t)\\
&\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
\end{aligned}\\
\end{gather*}
\begin{gather*}
\begin{aligned}
&\text{265}\\
&g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
&j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
&\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
&=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
\end{aligned}
\end{gather*}

\end{multicols*}

\end{document}

• Is this really a minimal example? Apr 19, 2014 at 9:09
• Other topic: Don't load inputenc with XeLaTeX. Apr 19, 2014 at 9:17
• Why precisely do you need 2 columns? Apr 19, 2014 at 10:24
• Use \raggedcolumns to fix this - you haven't provided many places for the columns to break... Apr 19, 2014 at 15:12
• @AndrewSwann I don't understand what is the problem. Also this doesn't solve it. It moves the first column up but not in the same height as the second one. Furthermore it leaves a lot of space in the first column.
Apr 21, 2014 at 16:58

With this approach, I build each block as a stack (with a 3pt buffer above and below), and then insert a \vspace{2ex}\par\vfil after each one. The 2ex is the minimum gap between blocks, and the \vfil will smooth out the whole look of the column (see alternative approach without this \vfil in 2nd part of the answer). After the final item in your multipage list, you can add a final\vfil so as to avoid excessive gapping from a partially filled column.

Within a block, the inter-item gap is specified in advance by \setstackgap{S}{6pt}. A block will not break in two across a column or page boundary, but the \vfil solution makes that look not so objectionable.

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\usepackage[utf8]{inputenc}

\setlength{\parindent}{0cm}

\usepackage{setspace}

\usepackage{xltxtra}
\usepackage{xgreek}
\setmainfont[Mapping=tex-text]{GFSDidot.otf}
\setsansfont[Mapping=tex-text]{GFSDidot.otf}

%\usepackage[fleqn]{amsmath}
\usepackage{amsmath}
\usepackage{unicode-math}

%\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}
\usepackage[usestackEOL]{stackengine}
\stackMath
\def\stackalignment{l}
\setstackgap{S}{6pt}
\begin{document}

\begin{multicols*}{2}
Preceding text\par
\SS{
\text{70}\\
e^{jz}=\cos z+j\sin z\\
\cos z=(1/2)(2\cos z)=\\
=(1/2)(2\cos z+j\sin z-j\sin z)=\\
=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
=(1/2)(e^{jz}+e^{-jz})
}
\SS{
\text{70}\\
e^{jz}=\cos z+j\sin z\\
\cos z=(1/2)(2\cos z)=\\
=(1/2)(2\cos z+j\sin z-j\sin z)=\\
=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
=(1/2)(e^{jz}+e^{-jz})
}
\SS{
\text{207}\\
x(t)=A_{c}\cos \theta(t)\\
\theta(t)=2\pi f_{c}t+\phi(t)\\
\phi(t)=K_{p}m(t)\\
x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
}
\SS{
\text{208}\\
x(t)=A_{c}\cos \theta(t)\\
\theta(t)=2\pi f_{c}t+\phi(t)\\
\dfrac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
}
\SS{
\text{208}\\
x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
\cos(a+b)=\cos a \cos b-\sin a \sin b\\
\phi(t)=K_{p}m(t)\\
\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
}
\SS{
\text{208}\\
x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
\cos(a+b)=\cos a \cos b-\sin a \sin b\\
\phi(t)=K_{p}m(t)\\
\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
}
\SS{
\text{208}\\
x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
\cos(a+b)=\cos a \cos b-\sin a \sin b\\
\phi(t)=K_{p}m(t)\\
\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
}
\SS{
\text{265}\\
g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
}
\SS{
\text{265}\\
g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
}
\vfil
\end{multicols*}

\end{document}

ALTERNATIVE APPROACH (without \vfil between blocks)

If one does not like the evenly spaced vertical column, and prefers a wide gap at column bottom, then defining

seems to resolve that (and also adds a 3pt buffer above/below each stack), as in

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\usepackage[utf8]{inputenc}

\setlength{\parindent}{0cm}

\usepackage{setspace}

\usepackage{xltxtra}
\usepackage{xgreek}
\setmainfont[Mapping=tex-text]{GFSDidot.otf}
\setsansfont[Mapping=tex-text]{GFSDidot.otf}

%\usepackage[fleqn]{amsmath}
\usepackage{amsmath}
\usepackage{unicode-math}

%\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}
\usepackage[usestackEOL]{stackengine}
\stackMath
\def\stackalignment{l}
\setstackgap{S}{6pt}
\begin{document}

\begin{multicols*}{2}
\SS{
\text{70}\\
e^{jz}=\cos z+j\sin z\\
\cos z=(1/2)(2\cos z)=\\
=(1/2)(2\cos z+j\sin z-j\sin z)=\\
=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
=(1/2)(e^{jz}+e^{-jz})
}
\SS{
\text{70}\\
e^{jz}=\cos z+j\sin z\\
\cos z=(1/2)(2\cos z)=\\
=(1/2)(2\cos z+j\sin z-j\sin z)=\\
=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
=(1/2)(e^{jz}+e^{-jz})
}
\SS{
\text{207}\\
x(t)=A_{c}\cos \theta(t)\\
\theta(t)=2\pi f_{c}t+\phi(t)\\
\phi(t)=K_{p}m(t)\\
x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
}
\SS{
\text{208}\\
x(t)=A_{c}\cos \theta(t)\\
\theta(t)=2\pi f_{c}t+\phi(t)\\
\dfrac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
}
\SS{
\text{265}\\
g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
}
\SS{
\text{265}\\
g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
}
\SS{
\text{265}\\
g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
}
\vfil
\end{multicols*}

\end{document}

• I tried to change \vspace{2ex}\par\vfil with cm instead ex and when I used large numbers like 5 or 7 cm I saw a difference but when I used 1 or 2 or 0.5 cm nothing was happening. Why? If I want for instanse no gap between the stacks what can I do?
Apr 22, 2014 at 1:11
• @Adam The minimum space between the blocks can be changed with the 2ex in the definition of \SS. The vfil in that same definition will force the gap after each item in the column to be "the same", so as to avoid an extra big gap at the bottom of the column. I don't have experience with multicolumn, but its vertical justification algorithms seem strange to me. I can manually add \rule{0pt}{5ex}\par after the last block in the 1st column to force space at the bottom of the column, but such a manual approach is not ideal. Let me think more on it. Apr 22, 2014 at 1:15
• Ok thank you very much! Why is that difficult?Why can't this just be a manual dicision writing for example \vspace{0ex}\par\vfil and to have your output? Also I didn't understand the role of the vfil.
Apr 22, 2014 at 1:22
• @Adam See revision (bottom of answer). The \vfil inserts a stretchy "rubber band" or "glue" between each stack. If the stacks don't fill up the whole column, the glue stretches between the top and bottom margins, providing equal spacing between each stack. Apr 22, 2014 at 1:25
• I saw it and I tried it. I kept the first one with the \par\vfil. It's far better.
Apr 22, 2014 at 1:46

You aren't allowing LaTeX any place to split the columns; if you really have such gigantic displays, then tell

\allowdisplaybreaks

The initial vertical space is due to beginning a paragraph with a display environment, which is wrong.

Here's a more minimalistic example:

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{multicol}

\setlength{\parindent}{0cm}

\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0cm}

\newcommand{\3}{\vspace{0.3cm}}

\title{}
\author{}
\date{}

\allowdisplaybreaks

\begin{document}
\raggedcolumns

\begin{multicols}{2}
70
\begin{gather*}
\begin{aligned}
&e^{jz}=\cos z+j\sin z\\
&\cos z=(1/2)(2\cos z)=\\
&=(1/2)(2\cos z+j\sin z-j\sin z)=\\
&=(1/2)(\cos z+j\sin z+\cos z-j\sin z)=\\
&=(1/2)(e^{jz}+e^{-jz})
\end{aligned}\\
\begin{aligned}
&\text{207}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\phi(t)=K_{p}m(t)\\
&x(t)=A_{c}\cos[2\pi f_{c}t+K_{p}m(t)]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos \theta(t)\\
&\theta(t)=2\pi f_{c}t+\phi(t)\\
&\frac{d\phi(t)}{dt}=2\pi K_{f}m(t)\Rightarrow\\
&\Rightarrow \phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\\
&x(t)=A_{c}\cos\left[2\pi f_{c}t+2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau\right]
\end{aligned}\\
\begin{aligned}
&\text{208}\\
&x(t)=A_{c}\cos\theta(t)=A_{c}\cos[2\pi f_{c}t+\phi(t)]\\
&\cos(a+b)=\cos a \cos b-\sin a \sin b\\
&\phi(t)=K_{p}m(t)\\
&\phi(t)=2\pi K_{f}\int\limits_{-\infty}^{t}m(\tau)d\tau
\end{aligned}\\
\begin{aligned}
&\text{265}\\
&g(t)=f(t)\ast h(t)=\int\limits_{-\infty}^{\infty}f(\tau)h(t-\tau)d\tau\\
&j(t)=\sum\limits_{k=-\infty}^{\infty}\delta(t-kT_{s})\Rightarrow\\
&\Rightarrow \mathcal{F}[j(t)]=\sum\limits_{k=-\infty}^{\infty}\mathcal{F}[\delta(t)]e^{j2\pi fkT_{s}}\\
&=\sum\limits_{k=-\infty}^{\infty}e^{j2\pi fkT_{s}}
\end{aligned}
\end{gather*}

\end{multicols}

\end{document}

Of course, balancing the columns is impossible because of the many aligned.

As an aside, note that inputenc should never be used when compiling with XeLaTeX or LuaLaTeX.

• Thank you. But even if I have text to begin the paragraph then there is still the same vertical space. And what about the two gather environments? Why is there a problem with them?