# How to align floats to a grid?

I try to use John Kormylo's idea for grid typesetting.

The command \resetbase works very well for nonfloating objects like equations or headings. But how can I use it after a float? When I add it directly after \end{figure} it does not help because Latex usually moves the floats away.

Any ideas?

MWE:

\documentclass[fleqn,twocolumn,12pt]{book}% Some compilations required.

\makeatletter
\def\raggedbottom{%
\def\@textbottom{\vskip \fill}\let\@texttop\relax}
\makeatother

\raggedbottom

\usepackage{geometry,amsmath,showframe,xparse}
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm}

\parindent=0pt
\parskip=\baselineskip
\jot=\baselineskip

\usepackage{tikzpagenodes}
\newlength{\baselineoffset}

\NewDocumentCommand{\resetbase}{}%
{\strut\tikz[remember picture, overlay]{\pgfextracty{\baselineoffset}%
{\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{current page text area}   {north}}}
\global\baselineoffset=\baselineoffset}%
\loop\ifdim\baselineoffset>\baselineskip
\repeat
\vspace{-\baselineoffset}\par}

\usepackage{eso-pic}
\begin{tikzpicture}
[remember picture,
overlay,
normal lines/.style={black!20, very thin}]
\draw [style=normal lines, step=\normalbaselineskip]  (current page.south west) grid (current page.north east);
\end{tikzpicture}}

\usepackage{lipsum}

\begin{document}

\chapter{Test}

\section{Test}

\resetbase {\bfseries Here we get the correct alignment. No problem after headings.}
\begin{align}
\sin \alpha & = \sqrt{\sqrt{\frac{\int dx}{\int f(x)dx}}} \\
\int \frac12 & = 1 \\
\sin \alpha & = \sqrt{\sqrt{\frac{\int dx}{\int f(x)dx}}}
\end{align}
\resetbase {\bfseries No problem after equations. But I don't know how to align floats.} \lipsum[1] Here the problem begins.
\begin{figure}
\centering
{\Huge $\int \frac{dx}{x} = \ln |x| + c$}
\vskip 20pt
{\large\bfseries How can I put a \string\resetbase{} after a float?}
\caption{Integral}
\end{figure}
{\bfseries No alignment! When I write \string\resetbase{} directly after \string\end \{figure\} it does not help because the float is usually moved away by \LaTeX .} \lipsum[1]

\end{document}


I tried it again using John Kormylo's \inspace. For nonfloating objects, it works, but the figure ist still not aligned.

What am I doing wrong?

MWE:

\documentclass[fleqn,twocolumn,12pt]{book}% Some compilations required.

\makeatletter
\def\raggedbottom{%
\def\@textbottom{\vskip \fill}\let\@texttop\relax}
\makeatother

\raggedbottom

\usepackage{geometry,amsmath,showframe,calc}
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm}

\usepackage{xparse}

\parindent=0pt
\parskip=\baselineskip
\jot=\baselineskip
\floatsep=\baselineskip
\textfloatsep=\baselineskip
\intextsep=\baselineskip
\abovecaptionskip=\normalbaselineskip
\belowcaptionskip=\normalbaselineskip

\usepackage{tikzpagenodes}
\newlength{\baselineoffset}

\NewDocumentCommand{\resetbase}{}% put baseline a multiple of \baselineskip below top of page
{\strut\tikz[remember picture, overlay]{\pgfextracty{\baselineoffset}%
{\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{current page text area}{north}}}
\global\baselineoffset=\baselineoffset}%
\loop\ifdim\baselineoffset>\baselineskip
\repeat
\vspace{-\baselineoffset}\par}

\usepackage{eso-pic}
\begin{tikzpicture}
[remember picture,
overlay,
normal lines/.style={black!20, very thin}]
\draw [style=normal lines, step=\normalbaselineskip]  (current page.south west) grid (current page.north east);
\end{tikzpicture}}

\newcommand{\inspace}[3][c]% #1 = t/c/b (optional), #2 = number of lines (0=compute), #3 = contents
{\bgroup
\setbox0=\vbox{#3}%
\count1=#2\relax
\def\test{#1}%
\ifnum\count1<1
\dimen0=\dimexpr \ht0+\dp0\relax
\count1=\numexpr \dimen0/\normalbaselineskip\relax
\fi
\dimen0=\normalbaselineskip
\multiply\dimen0 by \count1
\ifvmode
\noindent
\let\terminate=\par
\else
\newline
\let\terminate=\newline
\fi
\def\opt{t}% align to top
\ifx\test\opt\relax
\strut\rlap{\raisebox{\dimexpr \ht\strutbox-\ht0}[0pt][0pt]{\usebox0}}  \terminate
\else
\def\opt{b}% align to bottom
\ifx\test\opt\relax
\strut\rlap{\raisebox{\dimexpr \ht\strutbox+\dp0-\dimen0}[0pt][0pt]{\usebox0}}\terminate
\else% anything else is centered
\strut\rlap{\raisebox{\dimexpr \ht\strutbox-0.5\ht0+0.5\dp0-0.5\dimen0}[0pt][0pt]{\usebox0}}\terminate
\fi
\fi
\loop\ifnum\count1>1
\strut\terminate
\repeat
\egroup}

\usepackage{lipsum}

\begin{document}

\chapter{Test}

\section{Test}

\resetbase {\bfseries Here we get the correct alignment. No problem after headings.}
\inspace{0}{%
\begin{align}
\sin \alpha & = \sqrt{\sqrt{\frac{\int dx}{\int f(x)dx}}} \\
\int \frac12 & = 1 \\
\sin \alpha & = \sqrt{\sqrt{\frac{\int dx}{\int f(x)dx}}}
\end{align}}
{\bfseries No problem after equations with \string\inspace.} \lipsum[1] Here the problem begins.
\begin{figure}
\inspace[c]{0}{%
\centering
{\Huge $\int \frac{dx}{x} = \ln |x| + c$}
\vskip 20pt
{\large\bfseries Wy doesn't this work?}
\caption{Integral}}
\end{figure}
{\bfseries Still No alignment! What am I doing wrong?} \lipsum[1]

\end{document}


• you just need to make sure that your float box is a multiple of \baselineskip heigh and set \floatsep to be \baselineskip as well, also note that usage like {\Huge $\int \frac{dx}{x} = \ln |x| + c$} should always have a paragraph break before the } or you get Huge text on a normal baseline and very inconsistent line spacing – David Carlisle Apr 11 '18 at 20:43
• But how can I achieve this? How can I make the floatbox a multiple of \baselineskip? – user125730 Apr 11 '18 at 20:48
• – John Kormylo Apr 11 '18 at 21:27
• – David Carlisle Apr 11 '18 at 21:38