In a math formula, is there a way to put a number inside a square, as a decoration? I.e., instead of $\bar{1}$ or $\widehat{1}$ I would like to write something like $\insquare{1}$ and have the “1” inside a small square. Is this possible?

  • \fbox{1}? (Adjusting the with \fboxsep), but I think, there are fonts for this ;-) – user31729 Feb 16 '15 at 14:56

There are three simple options. One is \fbox{}, the content of which is typeset in text mode, but can handle math mode as well. Loading the amsmath package provides \boxed{}, the content of which is typeset in math mode. Both of these can be used in text or math mode (i.e., you don't need to enter math mode first). Loading the mathtools package provides \Aboxed{}, which is for placing part of an align environment in a box.

\usepackage{amsmath} % for \boxed{}
\usepackage{mathtools} % also loads amsmath



enter image description here

| improve this answer | |
  • it is horrible big, how to downsize the frame? – qrtLs Apr 24 '19 at 21:40
  • @ItsmeJulian I'm not sure I understand your question. Do you want minimal space between the character and the box, or are you referring to the size of the typeset page? – erik Apr 26 '19 at 13:43
  • in flowtext the box sticks out and should be tighter around the number, maybe even scale both down if possible? – qrtLs Apr 26 '19 at 19:15
  • 2
    @ItsmeJulian These solutions aren't suitable for flowing text, but something like \setlength{\fboxsep}{1pt} will adjust the box spacing. – erik Apr 26 '19 at 19:33

You can use \fbox in math mode:


But if you want to emphasise on something, there is \boxed (works like \fbox). When you want to put an equation line in a frame, \boxed doesn’t work and you will need to use \Aboxed from the mathtools package:

\Aboxed{x & = 1}
| improve this answer | |

Just for fun ;-)

\insquare[fboxsepvalue]{box content}[fboxrulewidth]

creates a box in math mode, with the content boxed, the optional value holds the separation value between frame and content, setting the rule width optionally

  \endgroup % Group safe lengths


\foreach \x in {1,...,10} {%


enter image description here

| improve this answer | |

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.