How to get a box including some text in text mode, which depth 0pt?
Asked
Active
Viewed 7,870 times
16
-
1Can 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 06:53
-
@Altermundus I want the M.S.'s answer! Thanks you too! – Stufazi Hoqckt Apr 25 '11 at 08:30
-
@M.S. No problem! – Stufazi Hoqckt Apr 25 '11 at 08: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
3 Answers
29
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.
Martin Scharrer
- 262,582
-
-
3Just 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
\heightis a command to get the natural height of<text>. – Micah Walter Jun 08 '15 at 16:11
13
\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}
-
@Herbert But if I use
\smash{a}in text mode, the letteraturned a math italic shape. – Stufazi Hoqckt Apr 25 '11 at 08:53 -
-
3@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
\smashin\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 -
-
@Stufazi Hoqckt:
\DeclareMathOperator*{\Sup}{su\smash{p}}this is set in math mode and the one with\raiseboxis set in text mode! With\textrm{\smash{p}}you also have it in text mode. – Apr 25 '11 at 13:23 -
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.
Alain Matthes
- 95,075
-
You should not modifiy the height and width, unless you are looking for "strange results"!!! – unbonpetit Apr 25 '11 at 08:09
-
1Thanks, I just want a box, inside it is some text, and the box is no depth. – Stufazi Hoqckt Apr 25 '11 at 08:32
