0

I want gray inside $\Box$. How can we do that? I will use this as a caption of my figure like

\caption{ $\Box$ denotes ...}
4
  • 1
    Probably better to use something like \fcolorbox{black}{gray}{\ } or similar. – daleif May 31 at 8:27
  • Not working. Do I need any usepackage? – Sanu May 31 at 8:41
  • 2
    xcolor, 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 at 8:49
  • It is working! Thanks a lot for your help. – Sanu May 31 at 8:54
2

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.

1

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}

enter image description here

If you're running LaTeX before the 2020-10-01 release, you also need

\usepackage{xparse}

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.