I got stuck on designing easy-to-use command wrappers for multipanel floats (i.e. subfigures/subtables) built around the

In the MWE below I have omitted top-aligned panels for brevity.
The panel-environment evaluates its contents and dumps them into a macro \panelcontents. Although it does nothing with this value, it does evaluate the contents' height and stores it in \currentpanelheight---I imagine the final version will have to do it anyway, to decide which panel is the tallest automatically.
The problem disappears if I specify the tallest panel's height by hand (line 89 of the MWE). It is to have LaTeX determine this value automatically for each row that poses a problem. I considered a solution where each panel exports a value to an external file, and a separate macro selects the tallest panel on a subsequent run, rather than on-the-fly. There is probably a more elegant way to do it, but I am missing a piece of the puzzle. Can anyone offer any advice?
Code: Select all
Code, edit and compile here:
\documentclass{book}\usepackage{subcaption}\usepackage[labelsep=space]{caption}%Housekeeping code\newlength\tallestpanelinrow\newlength\currentpanelheight\newlength\currentpanelwidth\newif\ifcenterpanels\newif\ifbottomalignpanels\newcommand{\CenterPanels}{%\centerpanelstrue\bottomalignpanelsfalse}%\newcommand{\BottomAlignPanels}{%\centerpanelsfalse\bottomalignpanelstrue}%\BottomAlignPanels%Row environments\newenvironment{Bpanelrow}{\par\BottomAlignPanels}{}%Centered panels dump contents in a savebox%for future repositioning\newsavebox{\rowpanelbox}\newenvironment{Cpanelrow}{\par\CenterPanels%\begin{lrbox}{\rowpanelbox}}%{\end{lrbox}%\usebox\rowpanelbox%}%The panel environment\newsavebox{\panelbox}\newenvironment{panel}[2][1.0]{%%Housekeeping code\setlength{\currentpanelwidth}{#1\textwidth}%