3

I need to know the dimensions of many objects in a given unit. Essentially I need the size \fboxes would have would I draw ones around the objects. Can I use the typeout command and a modified framebox command to print this information to the latex output?

3
  • 1
    What size you need to know : the framebox (with contents) or the contents of the framebox?
    – touhami
    Sep 5, 2015 at 8:32
  • Only contents would be good, but that's not what matters most. It could be the size of the box if that's much easier to get.
    – highsciguy
    Sep 5, 2015 at 8:35
  • If you know the size of the box, you can calculate the content size too. Do you use \fbox?
    – user31729
    Sep 5, 2015 at 8:48

1 Answer 1

4

Since it's not clear, what framebox actually is, I assume \fbox.

It's easy to use put the box content first in a \savebox, named, say,\mybox and ask for the width of it with \wd\mybox.

Putting \fbox around the content will additionally use 2\fboxrule and 2\fboxsep spaces around the normal content, see the output.

\documentclass{article}

\newbox\mybox
\newbox\myotherbox

\savebox{\mybox}{This is some text}
\savebox{\myotherbox}{\fbox{\usebox{\mybox}}}

\typeout{Box alone:\the\wd\mybox}
\typeout{Whole box:\the\wd\myotherbox}

\typeout{\the\dimexpr2\fboxsep+\the\dimexpr2\fboxrule}
\typeout{Sum of all: \the\dimexpr 2\fboxsep+2\fboxrule+\wd\mybox}


\begin{document}
\end{document}

This will print out:

Box alone:75.44455pt
Whole box:82.24454pt
6.79999pt
Sum of all: 82.24454pt
2
  • 1
    Excellent. The only thing I had to look up in addition was '\ht' for the height of the box.
    – highsciguy
    Sep 5, 2015 at 10:24
  • @highsciguy: Oh, sorry, how could I forget \ht and \dp, two important query routines
    – user31729
    Sep 5, 2015 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .