我如何导出调整框参数?

我如何导出调整框参数?

我有两个adjustboxes(来自调整框包装)。现在我需要赋予第二个盒子与第一个盒子相同的总高度。

\documentclass{article}
\usepackage{etex}
\usepackage[etex=true,export]{adjustbox}
\begin{document}

\begin{adjustbox}{width={\textwidth},totalheight={8cm},keepaspectratio}
...some content ...
\end{adjustbox}

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

\begin{adjustbox}{totalheight={<the same as in the first adjustbox>},keepaspectratio}
...other content...
\end{adjustbox}

\end{document}

我无法使用8cm(在实际文档中,有另一个变量而不是固定值),因为如果框太宽而需要缩小,高度可能会更小。Adjustbox 说将\totalheight包含此高度,但我如何导出它以在第二个框中重新使用?

答案1

adjustbox现在有用于此类内容的键。在您的情况下,用于gstore totalheight=\somelengthregister存储总高度。如果您需要更多尺寸,请查看gstore sizes包装手册第 4.14 节“存储包装盒内容”中描述的其他键。

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

\begin{document}

\begin{adjustbox}{width={\textwidth},totalheight={8cm},keepaspectratio,gstore totalheight=\mylength}
 ... some content ...
\end{adjustbox}

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

\begin{adjustbox}{totalheight=\mylength,keepaspectratio}
 ...other content...
\end{adjustbox}

\end{document}

原始答案

目前还没有用于存储 大小的键选项adjustbox,但我已经在考虑添加它们。 的值\totalheight只能用于影响大小的键。这些键实际上会装箱内容,因此会更新此长度以获得正确的值。但是,您可以使用使用键添加的一些小代码自己进行所需的装箱precode,方法是使用包的功能collectbox,该功能无论如何都在内部使用adjustbox。您需要一个全局分配的长度寄存器。

\documentclass{article}
\usepackage{etex}
\usepackage[etex=true,export]{adjustbox}
\newlength\mylength
\begin{document}

\begin{adjustbox}{width={\textwidth},totalheight={8cm},keepaspectratio,precode={\collectbox{\global\setlength\mylength{\totalheight}\BOXCONTENT}}}
  ... some content ...
\end{adjustbox}

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

\begin{adjustbox}{totalheight=\mylength,keepaspectratio}
 ...other content...
\end{adjustbox}

\end{document}

如果您更频繁地需要此功能,那么您可以为此定义一个新键:

\documentclass{article}
\usepackage{etex}
\usepackage[etex=true,export]{adjustbox}
\newlength\mylength

\makeatletter
\define@key{adjbox}{settototalheight}[1]{%
    \Gin@esetsize
    \@tempswatrue
    \adjust@addcode{\@collectbox{\global#1=\totalheight\relax\BOXCONTENT}}{}%
}
\makeatother

\begin{document}

\begin{adjustbox}{width={\textwidth},totalheight={8cm},keepaspectratio,settototalheight=\mylength}
  ... some content ...
\end{adjustbox}

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

\begin{adjustbox}{totalheight=\mylength,keepaspectratio}
 ...other content...
\end{adjustbox}

\end{document}

请注意,您需要在最后添加密钥,因为顺序很重要。

答案2

我看到的唯一方法是将第一个箱子放在储物箱中并测量

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

% in the document
\sbox{\stephenbox}
  {\begin{adjustbox}{width={\textwidth},totalheight={8cm},keepaspectratio}
   ...some content ...
   \end{adjustbox}}%
\setlength{\stephenlength}{\ht\stephenbox}%
\addtolength{\stephenlength}{\dp\stephenbox}%
\usebox{\stephenbox}

some lines later

\begin{adjustbox}{totalheight=\stephenlength,keepaspectratio}
...other content...
\end{adjustbox}

相关内容