# Context: Placing float (figure) and text-top at same height

I would like my figures to be flush with the text line beside them if they are positioned left or right and top. Currently the top edge of the figures are roughly flush with the 2nd line. This seems to be the standard position for floats e.g. look at the images at this page

Currently as:

Should be:

How can I set the top of my figures to be flush with the X-height of the 1st line? Is there a way to define an offset to shift the figure top? Or an more elegant solution? (I tried several commands, but did not find an appropriate one)

PS.: I use `\setuplayout[grid=yes]`

• You can try `\setupfloat[figure][sidealign=line]` – Marco May 30 '12 at 21:27

When typesetting images on a grid, several factors are involved. The first one is the presence of a caption or title.

## No caption

If no caption is provided, then the bottom of the images is aligned to the grid. The top alignment depends on the height of the image. To align the top to the x-height of the body font, the images need to have a multiple of the height of the base line distance plus the x-height of the body font.

``````\startplacefigure [location={none,left}]
\externalfigure [dummy] [height=\dimexpr2\lineheight+\exheight\relax]
\stopplacefigure
``````

However, the image is then aligned to the second line. To align it to the first line, as you requested, provide the option `high`.

``````\startplacefigure [location={none,left,high}]
\externalfigure [dummy] [height=\dimexpr2\lineheight+\exheight\relax]
\stopplacefigure
``````

## With caption

A caption makes things slightly more complicated. Between the float and the caption there is a `\blank` inserted, which shifts the image up. To align it to the base line, the depth of a strut needs to be compensated.

``````\setupcaptions [figure] [inbetween={\blank[\strutdepth]}]
``````

To align all figures to the first line, you can use the `sidealign` key globally. Then it is not necessary to specify the value with each figure.

``````\setupfloats [figure] [sidealign=line]
``````

## Fine tuning

Another option to fine tune the vertical placement of the floats is to use the command `\movesidefloat`. The argument can be eg. `+2*line` or `-1*line`. The command is used directly before the `\startplacefigure`.

## Documentation

Further details about float placement and grids are explained in the details manual.

## Complete example

``````\useMPlibrary        [dum]
\setuplayout         [grid=yes]
\setupinterlinespace [line=20pt]

\setupfloats   [figure] [sidealign=line]
\setupcaptions [figure] [inbetween={\blank[\strutdepth]}]

\starttext
\showgrid

\startplacefigure [title=A short caption, location=left]
\externalfigure [dummy] [height=\dimexpr2\lineheight+\exheight\relax]
\stopplacefigure
\input ward

\startplacefigure
[title={There is not so much basic instruction, as of now, as there was
in the old days, showing the differences between good and bad typographic design.},
location=left]
\externalfigure [dummy] [height=\dimexpr3\lineheight+\exheight\relax]
\stopplacefigure
\input zapf

\startplacefigure [title=Short caption, location=left]
\externalfigure [dummy] [height=\dimexpr5\lineheight+\exheight\relax]
\stopplacefigure
\input ward

\page

\movesidefloat [line]
\startplacefigure [location={none,left}]
\externalfigure [dummy] [height=\dimexpr2\lineheight+\exheight\relax]
\stopplacefigure
\input ward

\movesidefloat [line]
\startplacefigure [location={none,left}]
\externalfigure [dummy] [height=\dimexpr3\lineheight+\exheight\relax]
\stopplacefigure
\input zapf

\movesidefloat [line]
\startplacefigure [location={none,left}]
\externalfigure [dummy] [height=\dimexpr5\lineheight+\exheight\relax]
\stopplacefigure
\input ward

\stoptext
``````

• Thanks, that's very instructive! Could I perhaps ask you to add an example for aligning the caption e.g. `location={inner,high}`? I'd also be happy to make this a new question, but I somehow think it would be nicer to have it all in one place. – Florian Apr 4 '17 at 19:55