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'm writing a slideshow with beamer, with various slides containing trees (in the graph-theoretic sense). The talk I'm going to be using this slideshow for discusses how changing the label of a certain vertex can affect the label of another vertex elsewhere in the tree. To do this "before/after" , I'm using \only<1>{some label}\only<2>{some other label} in the relevant vertices; see minimal working example at the bottom of this post.

The problem with this example is that the new label is wider than the original one; given that the replacement happens on a vertex at one of the sides of the tree, it affects the width of the entire tree; given that the tree is centered, the transition from the old label to the new one makes the whole tree shift a bit.

To avoid this, I want to enclose the original label in a \makebox, and then use the width of the new label as the width of the box. My first idea was to use something like \makebox[\hphantom{the new label}][c]{old label}, but that simply inserts a \phantom box inside the \makebox, rather that declaring the width of the \makebox.

Obviously, I can do it the ugly way, i.e., by declaring the width of the \makebox in mm or whatever and then try different widths until I find the right one. What I'm looking for here is a more general solution.

\documentclass[dvips,11pt]{beamer}
\mode<presentation>

\usepackage{pstricks,pst-jtree}

\begin{document}

\begin{frame}
  \vfill
    \begin{center}
      \jtree[xunit=3.8em]
      \! = {some label}!a .
      \!a = <left>{some label} ^<right>{some label}!b .
      \!b = <left>{some label} ^<right>{\only<1>{old label}\only<2>{the new label}}!c .
      \!c = <vert>{some label} .
    \endjtree
  \end{center}
\vfill
\end{frame}

\end{document}
share|improve this question
    
To make it clear: this is a purely aesthetic issue. The .tex file compiles without problem. –  Koldito Sep 4 at 18:27

2 Answers 2

up vote 4 down vote accepted

calc offers \widthof{<stuff>} which returns the width (as a length) of <stuff>. As such you can use:

enter image description here

\documentclass[dvips,11pt]{beamer}
\mode<presentation>

\usepackage{pstricks,pst-jtree,calc}

\begin{document}

\begin{frame}
  \vfill
    \begin{center}
      \jtree[xunit=3.8em]
      \! = {some label}!a .
      \!a = <left>{some label} ^<right>{some label}!b .
      \!b = <left>{some label} ^<right>{\only<1>{\makebox[\widthof{the new label}]{old label}}\only<2>{the new label}}!c .
      \!c = <vert>{some label} .
    \endjtree
  \end{center}
\vfill
\end{frame}

\end{document}

It's also possible, depending on whether or not the width measurement is limited by expansion, to capture the width in a length elsewhere using

\newlength{\mywidth}
\settowidth{\mywidth}{the new label}

and then use \mywidth wherever you want to reference the width of the new label.

share|improve this answer
    
Thank you, that works. –  Koldito Sep 4 at 19:21

You can do that easily with the eqparbox package: instead of using a declared width, \eqparbox is an \mbox that defines a tag which can be used with the subsequent \eqparboxes: all \eqparboxes using this tag will have the same width as the first.

There are also \eqmakebox, \eqframebox, \eqsavebox commands and an eqminipage environment.

Demo:

\documentclass[11pt]{article}

\usepackage{pstricks,pst-jtree}
\usepackage{makebox, eqparbox}

\begin{document}

{\fboxsep=0pt\fbox{The new label}}

\eqparbox{new}{The new label}

\eqframebox[new]{Old label}

\end{document} 

enter image description here

share|improve this answer

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.