# fine-tuning of makebox width

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}

-
To make it clear: this is a purely aesthetic issue. The .tex file compiles without problem. – Koldito Sep 4 '14 at 18:27

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

\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.

-
Thank you, that works. – Koldito Sep 4 '14 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}


-