# How do I export adjustbox-parameters?

I have got two adjustboxes (from the adjustbox package). Now I need to give the second box the same totalheight as the one which the first box got.

\documentclass{article}
\usepackage{etex}
\begin{document}

...some content ...

(In between is some text and a page break.)

...other content...

\end{document}


I can't use the 8cm (in the real document there is another variable instead of a fixed value), because the height might be smaller if the box needed to be scaled down because it was too wide. Adjustbox says that \totalheight would contain this height, but how do I export this to be re-used in the second box?

-

There are no key options yet to store the size of an adjustbox, but I was already thinking to add them. The value of \totalheight can only be used in keys which affect the size. These actually box the content and therefore update this length to have the correct value. You can however do the required boxing yourself using some small code added using the precode key, by using features of the collectbox package, which is internally used by adjustbox anyway. You need a length register which is assigned globally.

\documentclass{article}
\usepackage{etex}
\newlength\mylength
\begin{document}

... some content ...

(In between is some text and a page break.)

...other content...

\end{document}


If you need this more often then you can define a new key for this:

\documentclass{article}
\usepackage{etex}
\newlength\mylength

\makeatletter
\Gin@esetsize
\@tempswatrue
}
\makeatother

\begin{document}

... some content ...

(In between is some text and a page break.)

...other content...

\end{document}


Note that you need to add the key at the very end, because the order is significant.

-
It works (as your answers always do), but I was really surprised that \fitsinglefig...\captionsetup...\begin{table}[H]\begin{leftfullpage}\raggedleft‌​\makeatletter\begin{adjustbox}{width={\textwidth},totalheight={\fitfigheight},kee‌​paspectratio,precode={\collectbox{\global\setlength\@tempdimc{\totalheight}\BOXCO‌​NTENT\xdef\ajbStotalheight{\@tempdimc}}}}\begin{tabular}...<end everything, new page>\noindent\captionsetup...\begin{table}[H]\begin{fullpage}\begin{adjustbox}{‌​valign=b,totalheight={\ajbStotalheight},keepaspectratio}\begin{tabular}... worked without any further problem! +1 and accepted. –  Stephen Apr 10 '12 at 15:29
Note that \xdef\ajbStotalheight{\@tempdimc} doesn't make much sense. Dimensions aren't expandable. Either write \the\@tempdimc instead of \@tempdimc to expand to its current value, or directly \xdef\ajbStotalheight{\the\totalheight}, before or after \BOXCONTENT. –  Martin Scharrer Apr 10 '12 at 15:40
The limited number of characters of a comment and the wrong place to shorten the code... - thanks for pointing it out! –  Stephen Apr 10 '12 at 15:51
@Stephen: I just added a key like this to adjustbox, but with a different name. It will be in the next release. –  Martin Scharrer May 16 '12 at 0:25

The only way I see is to set the first box in a storage bin and measure it

% in the preamble
\newsavebox{\stephenbox}
\newlength{\stephenlength}

% in the document
\sbox{\stephenbox}
...some content ...

While your solution generally works (+1), I had hoped for an "in-adjustbox-package-solution" instead of boxing and measuring it. Martin Scharrer provided that. Could have send an e-mail to him, because he is the author/maintainer of the adjustbox package, but his solution here could also help other people with a similar problem. - \end{leftfullpage} resets \stephenlength to 0pt, but I did not mention in my question that the adjustbox is inside a \makeatletter inside \raggedleft inside \begin{leftfullpage} inside \begin{table}[H] inside \captionsetup inside \fitsinglefig... –  Stephen Apr 10 '12 at 15:35
@Stephen While my hack works, a solution based on adjustbox keywords is surely better. –  egreg Apr 10 '12 at 15:38