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.

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)

share|improve this question
    
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 Jan 13 '12 at 13:56
    
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 Jan 13 '12 at 14:07
    
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 Jan 13 '12 at 14:08
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 Jan 13 '12 at 14:51
    
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 Jan 13 '12 at 15:26
add comment

5 Answers 5

up vote 23 down vote accepted

I made the following diagram for the adjustbox bundle. It will be part of the trimclip manual (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 from the code repository. The source code for this and all other diagrams are also available.

share|improve this answer
    
\height is also used in the LaTeX kernel for \ht\@tempboxa. So I think it can be a little bit irritate. –  Marco Daniel Jan 13 '12 at 19:45
    
@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 Jan 13 '12 at 19:59
add comment

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

share|improve this answer
add comment

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 and TeX by Topic) to understand the \hbox and \vbox well.

share|improve this answer
add comment

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 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} 
share|improve this answer
add comment

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).

share|improve this answer
add comment

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.