# Inline boxes: alternative to pifont's non-filled-but-shadowed box?

I often need to draw inline boxes in specific rgb-colors.

I really like how easy to use the pifont package is for this purpose. But just the filled boxes look as desired. The shadowish look of the other boxes does not really fit.

Is there any easy alternative to get "empty boxes" with the same dimensions (scaling with textsize)? If I could keep my syntax (e.g. \sqboxEmpty{predefined-color}) more or less would be perfect.

minimal example:

\documentclass[11pt,a4paper]{article}%
\usepackage{pifont}
\usepackage{xcolor}

% some color definitions
\definecolor{cblue}{RGB}{16,78,139}
\definecolor{cred}{RGB}{139,37,0}
\definecolor{cgreen}{RGB}{0,139,0}

% normal box
\newcommand{\sqbox}[1]{\textcolor{#1}{\ding{110}}}%
% empty box
\newcommand{\sqboxEmpty}[1]{\textcolor{#1}{\ding{111}}}%

\begin{document}
I like these.
\sqbox{cred}  \sqbox{cgreen} \sqbox{cblue}

I don't like these too much.
\sqboxEmpty{cred}  \sqboxEmpty{cgreen}  \sqboxEmpty{cblue}
\end{document}


You don't need special fonts for drawing squares.

\documentclass[11pt,a4paper]{article}%
\usepackage{xcolor}

% some color definitions
\definecolor{cblue}{RGB}{16,78,139}
\definecolor{cred}{RGB}{139,37,0}
\definecolor{cgreen}{RGB}{0,139,0}

% normal box
\newcommand{\sqboxs}{1.2ex}% the square size
\newcommand{\sqboxf}{0.6pt}% the border in \sqboxEmpty
\newcommand{\sqbox}[1]{\textcolor{#1}{\rule{\sqboxs}{\sqboxs}}}
% empty box
\newcommand{\sqboxEmpty}[1]{%
\begingroup
\setlength{\fboxrule}{\sqboxf}%
\setlength{\fboxsep}{-\fboxrule}%
\textcolor{#1}{\fbox{\rule{0pt}{\sqboxs}\rule{\sqboxs}{0pt}}}%
\endgroup
}

\begin{document}
I like these.
\sqbox{cred}  \sqbox{cgreen} \sqbox{cblue}

And also these.
\sqboxEmpty{cred}  \sqboxEmpty{cgreen}  \sqboxEmpty{cblue}
\end{document}


Modify \sqboxs and \sqboxf to suit.

• do you see a possibility to make the boldness of the border \newcommand{\sqboxf}{0.6pt} scale with the text size? But seems the best solution so far, thanks! – thewaywewalk Sep 15 '14 at 20:47
• @thewaywewalk I wouldn't do that; but you can use the approximate relation 1pt = 0.1em, so 0.6pt = 0.06em. Try the value in em that satisfies you; the em unit scales with the current font size. – egreg Sep 15 '14 at 20:56
• Why wouldn't you do that? Looks as desired! – thewaywewalk Sep 15 '14 at 21:00
• @thewaywewalk Not everything scales linearly. ;-) – egreg Sep 15 '14 at 21:01
• better than no scaling ;) – thewaywewalk Sep 15 '14 at 21:02

I don't know how to deal with pifont symbols for empty boxes (there are none, as far as I know), so switched to the bbding package, using its \SquareSolid and \Square commands.

However, those symbols seem to be a little bit larger than \ding{110} from pifont package.

\documentclass[11pt,a4paper]{article}%
\usepackage{xcolor}
\usepackage{bbding}%

% some color definitions
\definecolor{cblue}{RGB}{16,78,139}
\definecolor{cred}{RGB}{139,37,0}
\definecolor{cgreen}{RGB}{0,139,0}

% normal box
\newcommand{\sqbox}[1]{\textcolor{#1}{\SquareSolid}}
% empty box
\newcommand{\sqboxEmpty}[1]{%
\textcolor{#1}{\Square}%
}%

\begin{document}
I like these.
\sqbox{cred}  \sqbox{cgreen} \sqbox{cblue}

You will perhaps like these ones:
\sqboxEmpty{cred} \sqbox{cred}  \sqboxEmpty{cgreen}  \sqboxEmpty{cblue}
\end{document}


• good alternative! Unfortunately the borders are quite thin and I will see if I rather go with the more customizable approach of egreg. But maybe I can find also some more of these "ding"-something packages. Thanks! – thewaywewalk Sep 15 '14 at 20:55
• @thewaywewalk: Yes, that's a fair point -- the boundaries are thin. – user31729 Sep 16 '14 at 1:28

My example shows how to create desired boxes by primitive commands. This is an elementary exercise of usage of \vrule, \hrule, \hbox and \vbox.

\def\boxemptyO{1.1ex} \def\boxemptyI{\dimexpr\boxemptyO-.8pt\relax}
\def\boxempty{\leavevmode
\vbox{\hrule\hbox to\boxemptyO{\vrule height\boxemptyI\hfil\vrule}\hrule}}

Now, you can type: \boxempty, and you get, what you want.


If you want to colorize this box, you can define \boxemtycolored which depends on used color system in your document. For example, in LaTeX with xcolor package, you can define

\def\boxemptycolor#1{{\textcolor{#1}\boxempty}}

Now, you can type \boxemptycolor{red}.


Edit If you need to control the rule thickness (for example in the macro \boxemtyT), then you can define \hruleA and \vruleA and use them instead \hrule, \vrule. It is simple exercise still.

\def\boxemptyA{1.1ex} \def\boxemptyT{0.6pt}
\def\boxemptyI{\dimexpr\boxemptyA-2\dimexpr\boxemptyT\relax\relax}
\def\hruleA{\hrule height\boxemptyT}
\def\vruleA{\vrule width\boxemptyT}
\def\boxempty{\leavevmode \message{:::\the\boxemptyI}
\vbox{\hruleA\hbox to\boxemptyA{\vruleA height\boxemptyI\hfil\vruleA}\hruleA}}

• ... to continue here: but your solution doesn't have any advantage over egreg's approach, has it? – thewaywewalk Sep 16 '14 at 7:06
• Yes, there is no special advantage. My solution only shows that if one knows only 300 TeX primitives then one needn't to know thousands of LaTeX commands and LaTeX packages and their commands. Many tasks can be done by primitives as an simple exercise. This taks belongs to this type. – wipet Sep 16 '14 at 7:15

No tikz?????

\documentclass[11pt,a4paper]{article}%
\usepackage{tikz}

% some color definitions
\definecolor{cblue}{RGB}{16,78,139}
\definecolor{cred}{RGB}{139,37,0}
\definecolor{cgreen}{RGB}{0,139,0}

% normal box
\newcommand{\sqbox}[1]{%
\begin{tikzpicture}%[baseline={(a.base)}]
\fill[#1] (0,0) rectangle (1.2ex,1.2ex);
\end{tikzpicture}%
}
% empty box
\newcommand{\sqboxEmpty}[1]{%
\begin{tikzpicture}%[baseline={(a.base)}]
\draw[line width=0.6pt,#1] (0.5\pgflinewidth,0.5\pgflinewidth) rectangle (1.2ex-0.5\pgflinewidth,1.2ex-0.5\pgflinewidth);
\end{tikzpicture}%
}%

\begin{document}
I like these.
\sqbox{cred}  \sqbox{cgreen} \sqbox{cblue}

And also these.
\sqboxEmpty{cred}  \sqboxEmpty{cgreen} \sqboxEmpty{cgreen}  \sqbox{cblue}

And also these.
\sqboxEmpty{cred}  \sqboxEmpty{cgreen} \sqbox{cgreen}  \sqboxEmpty{cblue}
\end{document}


• Thanks, disadvantage of this solution is that solid boxes and empty boxes with the same parameters (consider line width=0.1em) have a different size (quite a bit, if plotted next to each other) and one needs to adjust the rectangle manually(?). – thewaywewalk Sep 16 '14 at 6:38
• @thewaywewalk Not any more ;-). See the update. – user11232 Sep 16 '14 at 6:47
• The problem is that \usepackage{tikz} loads 26 thousands lines of code in order to draw simple box. This is very different than to use six lines of code from my example. But, unfortunately, this fact isn't the main subject of interest of current programmers. – wipet Sep 16 '14 at 6:54
• @wipet That is a valid point. As I use Illustrator for all my other graphics I actually try to avoid tikz and used the pifont package in the first place, because it's slim. I think there are people considering this. – thewaywewalk Sep 16 '14 at 7:05
• @wipet Oh! come on, we are corrupted and addicted to tikz beyond repair ;-). And we live in an era of high performance computing and resources are not a problem. Also, we can't expect every one to know tex. On a serious note, I agree with your point. :-) – user11232 Sep 16 '14 at 8:44