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.

In LaTeX, is it possible to create an empty box that has exactly the dimensions of some content given?

Example:

\emptybox{abc}

would insert an empty box of the size as if "abc" was printed there.

share|improve this question

2 Answers 2

up vote 19 down vote accepted

You can use a phantom: \phantom{abc}

\phantom makes an invisible box whose height, depth and width are the same as those of the string used in the argument. There's also \vphantom, which makes an invisible box whose height and depth are the same as those of the string used in the argument, but the width is zero. Finally, \hphantom has the width of the string used in the argument, but its height and depth are zero.

share|improve this answer

See also, the related commands:

\settowidth{\mylength}{stuff}
\settoheight{\mylength}{stuff} % height above baseline
\settodepth{\mylength}{stuff}  % depth below baseline

Example:

\newlength{\mywidth}
\settowidth{\mywidth}{plugh}

\hspace*{\mywidth}Hello
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.