# How to align text position on both sides of a twocolumn layout

I'm pretty sure this problem has been adressed somewhere before but I can't find a solution anywhere, probably because I have no idea how to define/call this problem.

Pretty much everything that isn't normal text size has influence on the text vertical alignment between both columns, how can I force latex to align the position of the lines on each side of the two column layout?

Minimal example:

\documentclass[A4,12pt]{article}
\usepackage{blindtext,amsmath}
\begin{document}
\sloppy
\twocolumn
\section{Random Section}
\blindtext

\blindtext

\begin{align*}
\sum_i X(i) \cdot x
\end{align*}
\blindtext

\blindtext

\end{document}


notice how even the section title doesn't have an appropriate height such that the text on the second column lines up... or is this normal? Is it just me who has a problem with that?

-

## migrated from stackoverflow.comAug 4 '12 at 19:33

This question came from our site for professional and enthusiast programmers.

you're not the only one who has a problem with the (non)alignment of the section heading. and it's even worse if the section heading has more than one line. sadly, i have no solution. however, i did want to mention that you shouldn't leave a blank line between body text and display math that follows; it causes the vertical spacing to be even worse than some people think it is already. (if the text following the display starts a new paragraph, it's okay, even desirable, to leave a blank line there.) –  barbara beeton Aug 4 '12 at 20:41
The assume simplest solution is learning Context. LaTeX in not design for grid typesetting, and very difficult to convince to do that. Search for grid typesetting. –  Sveinung Aug 4 '12 at 22:41
Have you tried with grid.sty? –  Guido Aug 5 '12 at 20:19

Probably I'd try to re-adjust the lines in the collected columns back to grid alignment after each column has been collected. The following isn't perfect but it shows the basic technique.

\documentclass[a4paper,12pt]{article}
\usepackage{blindtext,amsmath}

\showboxdepth1

\def\myround#1{%
\dimen0#1\relax
\divide\dimen0 \mycountb
\multiply\dimen0\mycountb
}

\global\let\myset Y

\makeatletter

% 4 + 11 = 15
\baselineskip15pt
\normalbaselineskip\baselineskip

\newcount\mycountb
\mycountb\baselineskip

\let\old@makecol\@makecol

\def\@makecol{%
\old@makecol
\global\setbox1\vbox{}%
\setbox0\vbox{\unvbox\@outputbox
\loop
\ifnum\lastnodetype=\m@ne
\else
\ifcase\lastnodetype
%0 char
\showthe\lastnodetype
\or
%1 hlist
\setbox0\lastbox
\myround{\ht0}
\ht0 \dimen0
\myround{\dp0}
\dp0 \dimen0
\global\setbox1\vbox{\box0\unvbox1}%
\or
%2 vlist
\setbox0\lastbox
\myround{\ht0}
\ht0 \dimen0
\myround{\dp0}
\dp0 \dimen0
\global\setbox1\vbox{\box0\unvbox1}%
\or
%3 rule
\showthe\lastnodetype
\or
%4 ind
\showthe\lastnodetype
\or
%5 mark
\showthe\lastnodetype
\or
\showthe\lastnodetype
\or
%7 rule
\showthe\lastnodetype
\or
%8 disc
\showthe\lastnodetype
\or
%9 whatsit
\let\lastnodetype\m@ne
\or
%10 math
\showthe\lastnodetype
\or
%11 glue
\myround{\lastskip\unskip}%
\global\setbox1\vbox{\vskip\dimen0\unvbox1}%
\or
%12 kern
\myround{\lastskip\unskip}%
\global\setbox1\vbox{\vskip\dimen0\unvbox1}%
\or
%13 penalty
\unpenalty
\or
%14 unset
\showthe\lastnodetype
\or
%15 math mode nodes
\showthe\lastnodetype
\fi
\repeat
}%
\setbox\@outputbox\vbox to\@colht{%
\offinterlineskip
\myround{\ht0}
\ht0 \dimen0
\myround{\dp0}
\dp0 \dimen0
\box0
\box1
\vss
}%
}
\makeatother

\begin{document}

\sloppy
\twocolumn
\section{Random Section}
\blindtext

\blindtext

\begin{align*}
\sum_i X(i) \cdot x
\end{align*}
\blindtext

\blindtext

\end{document}

-

The grid package alone might not solve your issue, particularly after the align* environment. To get back to the grid, the \vskipnextgrid from the gridset package does help.

This approach will fail if there's too many elements that need to be forced back into the grid: if so, gridset will not be able to achieve stable values.

Here's a MWE (It's long to show the effect)

\documentclass{article}
\usepackage{blindtext,amsmath}
\usepackage{gridset}% gridset provides us with \vskipnextgrid
\usepackage[fontsize=12pt,% if you don't set the font size and the baseline
baseline=14pt]% here, things go wrong (I don't know why, since
{grid}%         it's supposed to have a default value for both)
\begin{document}
\sloppy
\twocolumn
\section{Random Section}
\blindtext[2]
\begin{align*}
\sum_i X(i) \cdot x
\end{align*}
\vskipnextgrid
\blindtext[2]
\section{Another Random Section}
\blindtext[2]\footnote{\blindtext}% Added a footnote to see if it
\begin{align*}%                     messes with the grid
\sum_i X(i) \cdot x
\end{align*}
\vskipnextgrid
\blindtext[2]
\end{document}

-