# How to get the height of current float?

I am using the sidecpation from the sidenotes package to typeset my captions into the margin. I would like these captions to be aligned with the top of the floats.

One can simply put the sidecaption command first within the float. However, in combination with subfigures, this breaks the numbering (here). As a result of this problem, I am putting the sidecaption command as last and reposition it using the optional offset argument. Doing so manually and achieving a consistent layout for a lot of figures is quite hard and I would like to automate that.

Giving the height of the current figure as offset, would solve this problem in a simple and straightforward manner. But how do I get this length?

Please note that I am not interested in the height of a single image but in the height of the entire float which may consist of several images in subfigure environments with individual subcaptions. It would be a bonus if the approach would also cover tabulars.

Other options to top-align the sidecaption are also appreciated. They should however fulfill the requirements stated here.

A short MWE:

\documentclass[a4paper,11pt]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{blindtext}

% \usepackage{etoolbox}
% \usepackage{calc}

\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip,
marginparwidth=43mm, marginparsep=1em}

% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
format=hang,                 % caption hangs behind label
justification=justified,
font=footnotesize            % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
format=plain, %indention=2em, % whole line for caption, with indent after first
justification=outerragged,    % caption is a normal paragraph
labelsep=newline,             % quad separator behind label
font=footnotesize             % all in small font size
}
\DeclareCaptionStyle{sidecaption}{
style = sidestyle,
format=plain,
labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
format=hang,
justification=raggedright
]{subcaption}

\begin{document}
\chapter{for the numbers}

\begin{figure}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-a}%
\caption{some text for a}
\label{fig:3:a}
\end{subfigure}%
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-b}
\caption{some text for b}
\label{fig:3:b}
\end{subfigure}%
\sidecaption[LoF][-2em]{I want to be aligned at the top of the float
\label{fig:3}
}
\end{figure}

\end{document}


If you want to align the \sidecaption to the entire float, simply put the contents (excepting the \sidecaption) into a minipage, then use \raisebox to move the baseline,

The value 7.69997pt was obtained by measuring the height of a \strut inside the caption.

\documentclass[a4paper,11pt]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{blindtext}

% \usepackage{etoolbox}
% \usepackage{calc}

\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip,
marginparwidth=43mm, marginparsep=1em}

% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
format=hang,                 % caption hangs behind label
justification=justified,
font=footnotesize            % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
format=plain, %indention=2em, % whole line for caption, with indent after first
justification=outerragged,    % caption is a normal paragraph
labelsep=newline,             % quad separator behind label
font=footnotesize             % all in small font size
}
\DeclareCaptionStyle{sidecaption}{
style = sidestyle,
format=plain,
labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
format=hang,
justification=raggedright
]{subcaption}

\begin{document}
\chapter{for the numbers}

\begin{figure}
\raisebox{\dimexpr 7.69997pt-\height}{\begin{minipage}{\textwidth}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-a}
\caption{some text for a}
\label{fig:3:a}
\end{subfigure}%
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-b}
\caption{some text for b}
\label{fig:3:b}
\end{subfigure}%
\end{minipage}}\nobreak
\sidecaption[LoF][-2em]{I want to be aligned at the top of the float
\label{fig:3}
}
\end{figure}

\end{document}


• I do not quite understand what it does but it works like a charm :) – Martin Mar 17 '17 at 20:21
• Horizontal alignment is done along the baseline. For text, the baseline is the bottom of letters (except for descenders like g and y). One can use \raisebox{-\height} to move the baseline to the top, no matter where it was originally. Note that while \sidecaption takes up no space, it can still force a line break (hence the \nobreak). – John Kormylo Mar 17 '17 at 21:44