share
TeX - LaTeXConfused with TeX terminology: height, depth, width
[+63] [5] propaganda
[2012-01-13 13:44:47]
[ tex-core boxes dimensions strut ]
[ https://tex.stackexchange.com/questions/40977/confused-with-tex-terminology-height-depth-width ]

The LaTeX reference card states for example

\strut box w/ ht and depth of “(”, zero width

I came to see text as a two dimensional feature, but I must be missing out on something...

(following was off-topic: by the way, im trying to find documentation on how to use \vbox, \hbox,… i.e. to align a hbox within a vbox to the right)

As I understand it text extends above the baseline by height and (possibly) drops below it by depth. For instance, the p has a depth. The width is just the width of the text. For documentation on \vbox \hbox etc. you can have a look at TeX by Topic. - Roelof Spijker
As @wh1t3 suggested, TeX by Topic is a good starting point. Also, for in-depth explanation I'd recommend The TeXbook. For a simple explanation on struts and text height, check The Not So Short Introduction to LaTeX, especially pages 49 and 133-136. - Count Zero
I changed the title to reflect that this is more a question on TeX than about LaTeX. You should be more precise in stating your final problem. - egreg
(1) I suggest you post another question to ask about the uses of \vbox and \hbox, as this topic isn't very closely related to that of the dimensions of a TeX box. - Mico
somehow, I interpreted height,width,depth as in a 3D box. now I see height and depth are ofcourse along the same axis with baseline as origin, thanks for the swift response and neat pictures and tips and advice! - propaganda
[+59] [2012-01-13 19:02:33] Martin Scharrer [ACCEPTED]

I made the following diagram for the adjustbox bundle. It will be part of the trimclip manual [1] (The trimclip package will be an extracted part of the current adjustbox package).

Box

As you can see the text lies on the baseline, the height is everything above it and the depth everything below it. Usually only some lower-case character and punctuation go below it. Both together is the totalheight. Note that the coordinate system for the depth is going down, i.e. it is always positive. The width is the normal width of the content.

The macros in the document show how to access these values in LaTeX macros like \raisebox (first line) or with a TeX box register called \br here (second line).

There are further diagram which explain the trimming and clipping of boxes. The current work-in-progress version of the manual with this diagrams can be downloaded as PDF [2] from the code repository [3]. The source code for this and all other diagrams [4] are also available.

[1] https://ctan.math.illinois.edu/macros/latex/contrib/adjustbox/trimclip.pdf
[2] http://cdn.bitbucket.org/martin_scharrer/adjustbox/downloads/trimclip.pdf
[3] https://bitbucket.org/martin_scharrer/adjustbox/downloads
[4] https://bitbucket.org/martin_scharrer/adjustbox/src/tip/man

\height is also used in the LaTeX kernel for \ht\@tempboxa. So I think it can be a little bit irritate. - Marco Daniel
@MarcoDaniel: \height is usually \ht\@tempboxa or \ht\someotherboxregister, same for \width and \depth. Only for \totalheight a temporary length register is used. These macros are just a higher-level LaTeX interface to the lower-level TeX code. - Martin Scharrer
1
[+45] [2012-01-13 14:24:59] Leo Liu

This is what you want:

enter image description here

And use the height and width of ( for \structbox:

enter image description here

You may need to read the TeXbook or similar books for Plain TeX (esp. free books TeX for the Impatient [1] and TeX by Topic [2]) to understand the \hbox and \vbox well.

[1] http://ctan.org/pkg/impatient
[2] http://ctan.org/pkg/texbytopic

2
[+26] [2012-01-13 14:02:58] yannisl

Indeed for TeX letters are three dimensional objects. TeX lines up characters at their baseline, what goes below the baseline is their depth.

enter image description here

As Feynman [1] once explained there are always different perspectives to out common understanding -- in this case -- the words three dimensional. For metafont there are multitude of dimensions describing a particular letter. Use the package layouts to see the values and generate the image above.

\documentclass{article}
\usepackage{layouts}
\begin{document}
\printparameterstrue 
\drawfontframelabel{\Huge\textbf{tangling}}
\fbox{\Huge m}\fbox{\Huge g}\fbox{\Huge t}
\end{document} 
[1] http://lesswrong.com/r/discussion/lw/99c/transcript_richard_feynman_on_why_questions/#thingrow_t3_99c

3
[+24] [2012-01-13 14:11:09] Mico

In TeX speak, every "box" -- think of a rectangle, except that the rectangle could have one or more of its "dimensions" set equal to zero -- has height, depth, and width. The width part has the obvious meaning, being measured along the horizontal axis. The height of a box is measured up from the baseline, and its depth is measured down from the baseline. (One could refer to the sum of the height and depth of a box as its "total" height.) For typesetting purposes, it's essential to know both the height and depth of a box because when TeX creates a line of text out of a series of boxes, the boxes need to be aligned on the baseline.

Two quick examples. The box that contains the lowercase letter x has positive height and width but zero depth because the letter doesn't reach below the baseline. The lowercase letter j, in contrast, would be encased by a box that has positive height, width, and depth because it has a descender (a component that reaches below the baseline).

The strut you bring up in your question is a special TeX box which has the height and depth of the parenthesis symbol -- ( -- but has zero width and is therefore invisible. Being able to insert such a special box is a very handy typographic tool, because it forces the box that encloses it and the other ("real") items in the group of boxes to have at least the height and depth of a parenthesis.

The following code demonstrates how inserting struts can make the output look more polished. (The formula I've come up with is obviously highly contrived!)

  • In the first version of the formula, all three surds (the square-root symbols) have different depths and heights. The formula's appearance isn't exactly dreadful, but there's a distracting element: whereas the q, x, and k symbols are nicely aligned along the baseline, the three surds provide a second "line of sight" that rises at a slight diagonal from left to right.

  • In the second formula, inserting a \mathstrut -- TeX's \mathstrut generates a "box" that has the same height and depth as a parenthesis and has zero width -- inside the arguments of the three \sqrt macros makes the surds all have the same height and depth. As a result, the "line of sight" created by the three surds is now also perfectly horizontal.

Hopefully, then, the insertion of the struts will make for a more polished and thereby more visually pleasing appearance of the overall formula.

 \documentclass{article}
 \begin{document}
 \noindent
 A simple formula without struts \ldots
 \[\sqrt{q} = \sqrt{x} + \sqrt{k}\]
 \ldots\ and with struts.
 \[\sqrt{\mathstrut q} = \sqrt{\mathstrut a} + \sqrt{\mathstrut k}\]
 \end{document}

enter image description here


(1) Very nice to read and the example makes it easy to see. - internet
4
[+18] [2012-01-13 14:02:44] Roelof Spijker

The following image is inspired by an image from the TeXBook and shows the different parameters:

TeX box dimensions

For more information about commands like \hbox and \vbox you can have a look at The TeXBook or TeX by Topic (or any other number of TeX related books, I assume).


5