[Tex/LaTex] How to align text position on both sides of a twocolumn layout

grid-typesettingtwo-column

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?

Best Answer

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.

enter image description here

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


\showboxdepth1
\showboxbreadth\maxdimen


\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}
\advance\dimen0 11pt
\ht0 \dimen0
\myround{\dp0}
\advance\dimen0 4pt
\dp0 \dimen0
\global\setbox1\vbox{\box0\unvbox1}%
\or
%2 vlist
\setbox0\lastbox
\myround{\ht0}
\advance\dimen0 11pt
\ht0 \dimen0
\myround{\dp0}
\advance\dimen0 4pt
\dp0 \dimen0
\global\setbox1\vbox{\box0\unvbox1}%
\or
%3 rule
\showthe\lastnodetype
\or
%4 ind
\showthe\lastnodetype
\or
%5 mark
\showthe\lastnodetype
\or
%6 adjust
\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}
\advance\dimen0 11pt
\ht0 \dimen0
\myround{\dp0}
\advance\dimen0 4pt
\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}
Related Question