13

How to get a box including some text in text mode, which depth 0pt?

  • 1
    Can you give a more precise question to adapt my answer? What you want to do exactly with your text ? – Alain Matthes Apr 25 '11 at 6:53
  • @Altermundus I want the M.S.'s answer! Thanks you too! – Stufazi Hoqckt Apr 25 '11 at 8:30
  • @M.S. No problem! – Stufazi Hoqckt Apr 25 '11 at 8:31
  • "at" replies are only seen by the addressee if you use the first few characters of the username. So "@Martin" or "@MartinScharrer" will get noticed but not "@M.S." – Matthew Leingang Apr 25 '11 at 11:34
  • @ Matthew, I got it. – Stufazi Hoqckt Apr 25 '11 at 11:37
24

You can use \raisebox to modify the official height and depth of some text:

\raisebox{0pt}[\height][0pt]{<text>}

This raises the text by 0pt (so not at all), keeps the official height identical to the original height and sets the depth to 0pt.

  • @M.S.That is exactly what I want! Thank you. – Stufazi Hoqckt Apr 25 '11 at 8:54
  • 3
    Just a note to clarify that the first optional parameter specifies the height (that is, x-height), and the second the depth (distance to lowest descender). And \height is a command to get the natural height of <text>. – Micah Walter Jun 8 '15 at 16:11
12

\smash{great} is a box with zero height and no depth

\documentclass{article}
\usepackage{amsmath}
\newsavebox\SBox
\begin{document}
\sbox\SBox{great}%
\the\wd\SBox\\
\the\ht\SBox\\
\the\dp\SBox

\sbox\SBox{\smash{great}}%
\the\wd\SBox\\
\the\ht\SBox\\
\the\dp\SBox

\sbox\SBox{\smash[b]{great}}%% Needs amsmath
\the\wd\SBox\\
\the\ht\SBox\\
\the\dp\SBox

\end{document}

enter image description here

  • @Herbert But if I use \smash{a} in text mode, the letter a turned a math italic shape. – Stufazi Hoqckt Apr 25 '11 at 8:53
  • no, that is not possible, only inside math you'll get an italic a. – user2478 Apr 25 '11 at 9:18
  • 2
    @Herbert: With amsmath you can also say \smash[b]{g} to get zero depth and unmodified height (there's also \smash[t]{...}. – egreg Apr 25 '11 at 10:03
  • @Herbert Ehh, I just put the \smash in \DeclareMathOperator, that is, \DeclareMathOperator*{\Sup}{su\smash{p}} and use $\Sup$. While \DeclareMathOperator*{\Sup}{su\raisebox[0pt]{\height][0pt]{p}} is good. – Stufazi Hoqckt Apr 25 '11 at 11:33
  • @egred: I know ... there is also a [bt]. But this is not the problem here ... – user2478 Apr 25 '11 at 13:20
3

I don't know exactly what you want to do but if you want a special box with special dim then you can try :

\newbox\mybox
\setbox\mybox=\hbox{}
\ht\mybox=10mm \dp\mybox=0pt \wd\mybox=20mm

But If you put some text in your initial \hbox, you can have some strange results ! When you make a box with some contents, height, depth and width depend of the context.

  • You should not modifiy the height and width, unless you are looking for "strange results"!!! – unbonpetit Apr 25 '11 at 8:09
  • 1
    Thanks, I just want a box, inside it is some text, and the box is no depth. – Stufazi Hoqckt Apr 25 '11 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.