I like using \boxed
to emphasize my answers in homework problem sets. However, whenever I use superscripts/exponents inside the box, the box becomes taller than it seems it should. This causes two problems: the box looks bad, and it pushes other lines of text around.
Here's an example. Notice that the line spacing doesn't get changed until I use an exponent inside a box.
Is there an alternative to \boxed
that won't have this problem? Or some other good way to solve this issue?
Best Answer
You can use
tikzmark
as from this answer by Andrew Stacey to mark the endpoints where you want the box. The\MyBox
macro as defined below accepts an optional first parameter which allows you to get fancy boxes.Notes:
Known Issues:
This won't work if the text crosses line boundaries. If this is an issue and you are willing to consider highlighting instead of a box you should refer to Cool Text Highlighting in LaTeX.
This version will not adjust properly for text that adjusts the vertical spacing (ex.
\dfrac{1}{2}
from theamsmath
package). However, an updated version of this that adjusts to the correct height is provided at A \boxed alternative with minimal spacing?Code: