In the previous post, I got help with creating boxes with black borders and custom fills.
How can I create other shapes like triangles, circles, rotated squares, etc. with custom fills.
I do not want to use tikz at this moment.
\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}}}
\newcommand{\sqboxblack}[1]{\setlength{\fboxsep}{0pt}\fbox{\sqbox{#1}}}
% empty box
\newcommand{\sqboxEmpty}[1]{%
\begingroup
\setlength{\fboxrule}{\sqboxf}%
\setlength{\fboxsep}{-\fboxrule}%
\textcolor{#1}{\fbox{\rule{0pt}{\sqboxs}\rule{\sqboxs}{0pt}}}%
\endgroup
}
\newcommand{\sqboxEmptyblack}[1]{\setlength{\fboxsep}{0pt}\fbox{\sqboxEmpty{#1}}}
\begin{document}
I like these.
\sqbox{cred} \sqbox{cgreen} \sqbox{cblue}
And also these.
\sqboxEmpty{cred} \sqboxEmpty{cgreen} \sqboxEmpty{cblue}
\end{document}
Best Answer
I approve of your decision not to use TikZ. You can create various shapes by low level PDF commands, as is used in my code here. We define
\sqbox
for square,\trianbox
for triangle,\uptrianbox
for rotated triangle,\circbox
for circle and\diabox
for diamonds. All these macros have two parameters: first one is0
if we need outlined shape or1
if we need solid shape. Second one is the color defined by\def\nameCOLOR
.The result:
You need not any package for this. Nor
xcolor
. All stuff is done at PDF low level commands. If you are using XeTeX (no pdfTeX) then you need to define\pdfliteral
by:I tried this in plain TeX but I hope that the code will work in LaTeX too (after adding
\documentclass
etc. sequences).