![内联框:pifont 的非填充但有阴影的框的替代品?](https://linux22.com/image/297832/%E5%86%85%E8%81%94%E6%A1%86%EF%BC%9Apifont%20%E7%9A%84%E9%9D%9E%E5%A1%AB%E5%85%85%E4%BD%86%E6%9C%89%E9%98%B4%E5%BD%B1%E7%9A%84%E6%A1%86%E7%9A%84%E6%9B%BF%E4%BB%A3%E5%93%81%EF%BC%9F.png)
我经常需要用特定的 rgb 颜色绘制内联框。
我真的很喜欢它的易用性皮丰特包装就是为了这个目的。但只有填满的盒子看起来符合要求。其他盒子的阴影外观不太合适。
有没有其他简单的方法可以获得具有相同尺寸的“空框”(使用文本大小缩放)?如果我可以保留我的语法(例如\sqboxEmpty{predefined-color}
)或多或少会很完美。
最小示例:
\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}
答案1
绘制正方形并不需要特殊的字体。
\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}
修改\sqboxs
并\sqboxf
适应。
答案2
我不知道如何处理pifont
空框的符号(据我所知,没有),因此切换到包bbding
,使用它的\SquareSolid
和\Square
命令。
\ding{110}
然而,这些符号似乎比包装上的要大一些pifont
。
\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}
答案3
我的示例展示了如何通过原始命令创建所需的框。这是\vrule
、\hrule
和\hbox
用法的基本练习\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.
如果要为该框着色,您可以\boxemtycolored
根据文档中使用的颜色系统进行定义。例如,在带有xcolor
包的 LaTeX 中,您可以定义
\def\boxemptycolor#1{{\textcolor{#1}\boxempty}}
Now, you can type \boxemptycolor{red}.
编辑如果您需要控制规则厚度(例如在宏中\boxemtyT
),那么您可以定义\hruleA
和\vruleA
并使用它们代替\hrule
。\vrule
这仍然是简单的练习。
\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}}
答案4
不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}