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?
- 1,093
- 6,161
3 Answers
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.
\documentclass{article}
\usepackage{amsmath} % for \boxed{}
\usepackage{mathtools} % also loads amsmath
\begin{document}
\fbox{foo}
\(\fbox{$\delta$}\)
\boxed{foo}
\(\boxed{\delta}\)
\begin{align}
y&=x\\
\Aboxed{y&=x^2}
\end{align}
\end{document}

- 12,673
-
1
-
@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? – droid192 Apr 26 '19 at 19:15
-
3@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:
\fbox{1}
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}
- 1,093
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
\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{mathtools}
\NewDocumentCommand{\insquare}{omo}{%
\begingroup
\IfValueTF{#1}{%
\setlength{\fboxsep}{#1}%
}{%
}%
\IfValueTF{#3}{%
\setlength{\fboxrule}{#3}%
}{}%
\ensuremath{\fbox{#2}}
\endgroup % Group safe lengths
}%
\usepackage{pgffor}
\begin{document}
\foreach \x in {1,...,10} {%
\textcolor{blue}{\insquare[\x1pt]{\x}[\x0.5pt]}
}%
\end{document}

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