I want to put individual words in to boxes next to each other. I've used the
\framebox command, but this has produced different sized boxes around each word. How could I get all the boxes to be the same size around, e.g. [This] [is] [an] [example]?
Hence to get the frames to a fixed size, you need to fix the size of the boxes you give it.
Increase the "height" of the boxes
The most common desire is to set the total height of the boxes. Total height, because what we commonly refer to the "height" is actually the sum of two lengths: the height of the box, that for text depends on ascenders, and its depth, that for text depends on descenders.
If you want to create frames that are taller than the original boxes, it's easy: you simply put inside the boxes an invisible element (i.e. of zero width) of the desired height and depth. Such an element is very common in typography and has a name: a strut.
The default strut in LaTeX,
If that height doesn't suit you, you simply need to define your own strut. Let's say we want a depth of only 5% of the baseline skip and a height of 195% of it (note that the last argument of
Increase or decrease the "height" of the boxes
So the previous technique with struts works in most desired cases, but the particular example I choose also shows the limits of this technique (look closely at the bottom borders): the boxes will only fit exactly around the struts if the struts are the tallest and deepest elements. If the remaining content is taller or deeper than your custom strut, due for example to the "p" in our example, the box will accommodate that extra height.
Now what if you want a framed box that might be smaller than your content? Well, you simply make TeX believe that your content is the size you target (say a height of 15% of the baseline skip, and a depth of 5% of it), using a
Set the width of the boxes
Finally, if you also want to set the width of the boxes, you can include the content in boxes of fixed width with horizontal stretch or shrink glue on each size (
The reason here is that the contents has different heights/depths. One way around this would be to use a
Not to take any merit away from Xavier's nice and very detailed answer, here is a possibly quicker method. The main problem in this kind of jobs is to avoid increasing the interline space, so I reduce (uniformly) the padding around the text, still using the strut for having uniform height and depth.