# Align figure on a grid by it's top edge

I'm trying to place figures in a book that I'm typesetting. Most of them end up at the top of a page. I'd like my captions to use smaller font with a smaller line spacing than the main text of the book.

\usemodule[visual] % for fake words and images
\useMPlibrary[dum]

\setuppapersize[B5]

\setuplayout[
backspace=25mm,
topspace=20mm,
width=131mm,
height=200mm,
footer=0mm,
grid=yes]
\showgrid

\setupinterlinespace[
line=3.5ex]

\setupbodyfont[serif,12pt]

\setupcaptions[figure][
number=no,
style={\itx\setupinterlinespace[small]}]

\starttext

\startplacefigure[
location=top,
title={\fakenwords{30}{0}}]
\externalfigure[dummy][width=\textwidth,height=7cm]
\stopplacefigure

\fakenwords{80}{1} \par
\fakenwords{80}{2}

\stoptext


From what I see ConTeXt aligns floats on a grid by the bottom line of a caption. The result is that the top of the image ends up at random height depending on the image height and the number of lines in the caption.

My goal is to align the top edge of the image at the X-height of the top line, so that it matches text on the facing page. Any neccessary whitespace should go below the caption. It there a way to achieve it without manualy adjusting each float?

You can do it by overriding the float placement command in the output routine. I simply copied the original command \page_one_command_flush_float_box, renamed it and removed \snaptogrid.

\usemodule[visual] % for fake words and images
\useMPlibrary[dum]

\setuppapersize[B5]

\setuplayout
[backspace=25mm,
topspace=20mm,
width=131mm,
height=200mm,
footer=0mm,
grid=yes]

\showgrid

\setupinterlinespace[line=3.5ex]

\setupbodyfont[serif,12pt]

\setupcaptions
[figure]
[number=no,
style={\itx\setupinterlinespace[small]}]

\unexpanded\def\dontsnapfloatbox % \page_one_command_flush_float_box
{\expandafter\ifconditional\csname c_page_floats_center_box\endcsname
\ifdim\wd\floatbox<\hsize
\global\setbox\floatbox\hpack to \hsize{\hss\box\floatbox\hss}%
\fi
\fi
\hpack{\box\floatbox}}

\setupoutputroutine
[singlecolumn]
[page_otr_command_flush_float_box=\dontsnapfloatbox]

\starttext

\startplacefigure
[location=top,
title={\fakenwords{30}{0}}]
\externalfigure[dummy][width=\textwidth,height=7cm]
\stopplacefigure

\fakenwords{80}{1} \par
\fakenwords{80}{2}

\stoptext