[Tex/LaTex] How to make a 0pt height box

boxheight

We can use \makebox[0pt]{text} to make a box that is logically 0pt width to external (as if nothing existed to the surroundings, while actually we can put whatever in it).
My questions is—what is the counterpart command to make the height of a box appear to be 0pt, logically, to its adjacent boxes.
With such a box, after a \newline, next line will appear at the vertical position of the previous line on the same page.

Best Answer

To answer your written question: you can remove the height of a box by storing into a box register and set the height to 0pt and then use that box. You might also want to set the depth to 0pt. Ways of easily do this is the adjustbox package: \adjustbox{set height=0pt, set depth=0pt}{Some Text} or, without a package, \raisebox{0pt}[0pt][0pt]{Some Text}.

Note that this just makes the box have no official vertical size, but it is still placed in a horizontal list which makes up the line. Inside a paragraph all characters and other material like images are modeled by TeX as boxes with a height, depth and width and placed on a list which makes up a line, until enough is there to build a full line. All of these boxes sit on a line, the baseline, everything above that line makes up the height, everything below the depth. TeX usually places the amount \baselineskip between the baselines of two sequential lines.

Therefore if you want to overprint the following line over the last line, deleting the official height and depth of the content of the first line has no effect, because the baselineskip is still added. In order to achieve this you need to undo the baselineskip again so that the second line starts at the same vertical position as the first. This can be done using \vspace{-\baselineskip} between the two lines, in most cases. Note that if the first line contains material with a very large depth, then the two lines will be more than \baselineskip apart! Also if you have a paragraph break there then LaTeX might add more space between the last line of the last paragraph and the first line of the following paragraph depending on global settings (e.g. using the parskip package; used to get German paragraph style). Also LaTeX tries to spread the paragraphs across the page if \flushbottom is active by increasing inter-paragraph spacing. In such cases, you might want to use \\ instead of \par.

Related Question