I want gray inside $\Box$. How can we do that? I will use this as a caption of my figure like
\caption{ $\Box$ denotes ...}
The easiest method is probably something like
\documentclass[a4paper]{article}
\usepackage{xcolor}
\begin{document}
{\fboxsep=0pt\fbox{\color{gray}\rule{3mm}{3mm}}}
\end{document}
\fbox has some padding, which we locally remove by setting \fboxsep to zero.
You possibly want squares with different colors. The following \csq command will change size according to the context.
\documentclass{article}
\usepackage{xcolor}
\NewDocumentCommand{\csq}{om}{%
% colored square
% #1 = color model (optional)
% #2 = color spec
\IfNoValueTF{#1}{%
\textcolor{#2}{\rule{1.2ex}{1.2ex}}%
}{%
\textcolor[#1]{#2}{\rule{1.2ex}{1.2ex}}%
}%
}
\begin{document}
\csq{gray} denotes something
\csq[rgb]{0.1,0.3,0.9} denotes something else
\csq{red!40!blue} something completely different
{\Large\csq{gray} Large}
\end{document}
If you're running LaTeX before the 2020-10-01 release, you also need
\usepackage{xparse}
\fcolorbox{black}{gray}{\ }or similar. – daleif May 31 '21 at 08:27xcolor, though{\fboxsep=0pt\fbox{\color{gray}\rule{3mm}{3mm}}}might be better, more squareish. Please note you should never provide sniplets like this, always use minimal examples including document class and relevant preamble. Then we know what you are working with. – daleif May 31 '21 at 08:49