Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
It doesn't make much sense putting a \includgraphics into a minipage. Also I would use width and/or height not scale to determine the size. You can put the image into a savebox and measure its size. Which class and layout do you like to use for this document? –  Martin Scharrer Oct 4 '11 at 11:56
    
\documentclass[a4paper]{report}, right using the minipage here is not that useful, I just thought it might be possible crating an empty copy of it to the right somehow. How do I do this with the savebox? –  D.Roepo Oct 4 '11 at 12:01
add comment

2 Answers

up vote 4 down vote accepted

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}}
share|improve this answer
    
Thanks a lot. This is really nice! Could you for a novice as me comment a bit on what exactly is going on in your environment definition? Also is the slide indented, which, when making it .5\textwidth wide, results in the comment hanging over into the right side margin. Is there a work around? –  D.Roepo Oct 4 '11 at 17:36
    
@user7091 Such an environment should be set inside a center environment. I'll add some explanations later. –  egreg Oct 4 '11 at 17:41
add comment

It doesn't make much sense putting a \includgraphics into a minipage. Also I would use width and/or height not scale to determine the size. You can put the image into a savebox and measure its size.

Something along the lines of:

\documentclass{article}

\usepackage{graphicx}

\newsavebox\mysavebox

\begin{document}

\sbox\mysavebox{\includegraphics[width=.49\textwidth]{image}}
\usebox\mysavebox\hfill
\fbox{\begin{minipage}[b][\ht\mysavebox][t]{.49\textwidth}%
your text
\end{minipage}}

\end{document}

This however makes the framed minipage have a depth of \fboxsep which you can correct using e.g. \raisebox{\fboxsep}{..}. Using the adjustbox package would simplify these combinations:

\documentclass{article}

\usepackage{adjustbox}

\newsavebox\mysavebox

\begin{document}

\sbox\mysavebox{\includegraphics[width=.49\textwidth]{image}}
\usebox\mysavebox\hfill
\begin{adjustbox}{minipage=[b][\ht\mysavebox-2\fboxsep][t]{.49\textwidth},fbox,raise=\fboxsep}%
your text your text your text your text your text your text your text your text your text your text
your text your text your text your text your text your text your text your text your text your text
your text your text your text your text your text your text your text your text your text your text
your text your text your text your text your text your text your text your text your text your text
your text your text your text your text your text your text your text your text your text your text
your text your text your text your text your text
\end{adjustbox}

\end{document}

I added a tight frame around the image so the correct size and alignment can be shown. Simply remove it later.

Result

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.