[Tex/LaTex] Framed minipage of dependent dimensions

framedminipage

I am trying to prepare handouts of a ppt (I know). I would like a slide to be shown on the left half of a page and comments regarding it in a framed box of the same size as the slide on the right half. By

\begin{minipage}{.5\textwidth}
    \includegraphics[page=4,scale=.3]{my_ppt}
\end{minipage}

I can get the slide in, but how do I create a minipage to the right of it that has the same height as the previous minipage?

Is minipage the environment of choice here? And is the framed package the best way to get a frame around it?

Best Answer

An environment form can be obtained as follows

\newsavebox\pptbox
\newenvironment{pptcomment}[2][]
  {\sbox\pptbox{\includegraphics[#1]{#2}}%
   \dimen0=\ht\pptbox
   \parbox{.5\textwidth}{\centering\usebox\pptbox}%
   \begin{lrbox}{\pptbox}\begin{minipage}[c][\dimexpr\dimen0-2\fboxsep\relax][c]
     {\dimexpr.5\textwidth-2\fboxsep\relax}}
  {\end{minipage}\end{lrbox}\fbox{\box\pptbox}}

and then used as

\begin{pptcomment}[page=4,scale=.3]{my_ppt}
The comment text that will be vertically centered
with respect to the image on its left
\end{pptcomment}

In other words, you pass the new environment the same parameters you'd pass to \includegraphics. However, setting scale is not recommended.

How does this work?

We allocate a new bin \pptbox for storing objects; the first use of it is for measuring the height of the image (\ht\pptbox, which is stored in the temporary dimension register \dimen0). Then we typeset the image in a \parbox so that it will be vertically centered with respect to other objects. Next we open lrbox, which is the "environment form of \mbox, storing the contents again in the \pptbox bin. This box consists of a minipage vertically centered ([c]), as high as \dimen0 (i.e., the height of the image) minus twice the clearance between a box and the frame (\fboxsep); the contents of this minipage will be centered with respect to the total height; finally the minipage will be as wide as half the textwidth. The contents of the environment is read in and then the bin is wrapped up (\end{lrbox}) and used inside \fbox.

It's best to use pptcomment inside a center environment, which can also be inserted directly in the environment:

\newsavebox\pptbox
\newenvironment{pptcomment}[2][]
  {\begin{center}
   \sbox\pptbox{\includegraphics[#1]{#2}}%
   \dimen0=\ht\pptbox
   \parbox{.5\textwidth}{\centering\usebox\pptbox}%
   \begin{lrbox}{\pptbox}\begin{minipage}[c][\dimexpr\dimen0-2\fboxsep\relax][c]
     {\dimexpr.5\textwidth-2\fboxsep\relax}}
  {\end{minipage}\end{lrbox}\fbox{\box\pptbox}
   \end{center}}