Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Finding the width of a letter, word, or phrase

Put the word in a box, and measure the width of the box. For example,

\newdimen\stringwidth
\setbox0=\hbox{hi}
\stringwidth=\wd0

Note that if the quantity in the \hbox is a phrase, the actual measurement only approximates the width that the phrase will occupy in running text, since the inter-word glue can be adjusted in paragraph mode.

The same sort of thing is expressed in LaTeX by:

\newlength{\gnat}
\settowidth{\gnat}{\textbf{small}}

This sets the value of the length command \gnat to the width of “small” in bold-face text.


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=findwidth

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.