tikzsymbols
定义一系列可用于文本(或嵌套在较大的图片中)的符号,并且可以以各种方式进行定制,例如缩放大小、选择颜色等。
例如:
\documentclass[10pt,tikz]{standalone}
\usepackage{tikzsymbols}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (yellow) {\color{yellow}\Innocey};
\node [right=5pt of yellow] {\color{purple}\Innocey[13][][pink]};
\end{tikzpicture}
\end{document}
设置这种符号的最佳方法是什么?特别是,对现有软件包未涵盖的符号进行编码的最佳方法是什么?我打算将这个问题作为一个一般性问题,但我对旨在补充现有解决方案所提供的符号的符号特别感兴趣。
例如,假设我想创建一个“魔鬼”符号来补充上面的“天使”符号。最好的方法是什么?
最初,我通过修改用于生成光环笑脸的代码来实现这一点tikzsymbols
。但是,这依赖于内部宏,这些宏在包更新时消失或被重命名。所以我不得不重新编码我的符号以反映这些变化。
另一方面,如果我不使用这些宏,我不确定如何确保我的扩展与包提供的符号相辅相成。例如,如果我在每种情况下指定相同的缩放因子,我希望两个笑脸基于相同大小的圆圈。我希望基本线宽匹配等等。如果我从头开始编写我的符号,我担心,虽然代码在tikzsymbols
更新时不太容易被破坏,但我的符号的样式不太可能继续与包的符号相匹配。
为了完整起见,下面是我更新后的代码:
\documentclass[10pt,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending,positioning,fit,backgrounds}
\usepackage{tikzsymbols}
\makeatletter
\tkzsymbls@Declare@Robust@Commandx{Devilish}[3][1=1,2={opacity=0},3=red,usedefault]{% based on \Innocey from tikzsymbols - updated 2014-11-15 due to changes in tikzsymbols (untested here but tested in scratch)
\tikzsymbols@ifsaveboxundefined{Devilish#1#2#3}{%
\set@tkzsymblsscl{#1}%
\iftikzymbols@draftabsolute%
\tksymbls@bx@Prmtrstore{#1}%
\tikzsymbols@draftbox{1.73ex*\real{\tkzsymbls@Prmtr}}{1.909ex*\real{\tkzsymbls@Prmtr}}%
\else%
\ifdim\tkzsymbls@scl<0pt\set@tkzsymblsscl{-#1}\fi%
\begin{tikzpicture}[x=2.4ex, y=2.4ex, line width=0.12ex*\tkzsymbls@scl,scale=#1]
\fill [line width=0.05ex*\tkzsymbls@scl, #2, even odd rule] (0.25,0.47) arc (52:-52:0.17 and 0.14) (0.25,0.47) arc (50:-50:0.20 and 0.19) (-0.25,0.47) arc (128:232:0.17 and 0.14) (-0.25,0.47) arc (130:230:0.20 and 0.19);
\draw [line width=0.05ex*\tkzsymbls@scl, #3] (0.25,0.47) arc (52:-52:0.17 and 0.14) (0.25,0.47) arc (50:-50:0.20 and 0.19) (-0.25,0.47) arc (128:232:0.17 and 0.14) (-0.25,0.47) arc (130:230:0.20 and 0.19);
\fill [#2] (0,0) circle (0.33);
\draw (0,0) circle (0.33);
\fill (-0.1,0.075) circle (0.075);
\fill (0.1,0.075) circle (0.075);
\draw (-0.2,-0.1) .. controls (-0.1,-0.2) and (0.1,-0.2) .. (0.2,-0.1);
\draw [line cap=round] (0.075,0.12) -- (0.175,0.2) (-0.075,0.12) -- (-0.175,0.2);
\draw [line width=0.075ex*\tkzsymbls@scl, #3, -{Stealth[bend,length=#1*.4ex]}] (0.1,-.325) to [out=-90, in=-125] (.3,-.3) to [out=55, in=125] (.45,-.15) to [out=-55, in=-60] (.4,-.25) to [out=120, in=-160] (.5,-.2) to [out=20, in=-155] (.4,.175) to [out=25, in=-80] (.45,.3);
\end{tikzpicture}%
\fi%
}%
\tikzsymbols@use@box{Devilish#1#2#3}%
\tikzsymbolsaftersymbolinput%
}
\tkzsymbls@Declare@Robust@Command{wDevilish}[1][3]{\Devilish[#1][opacity=0][black]}
\makeatother
\begin{document}
\begin{tikzpicture}
\node (green) {\color{green}\Devilish[5][][green]};
\node (red) [right=5pt of green] {\color{red}\Devilish[13][][red]};
\begin{scope}[on background layer]
\node [draw, fill=black, fit=(green) (red)] {};
\end{scope}
\end{tikzpicture}
\end{document}
或者在这种情况下真的没有最好的方法吗?也就是说,任何方法都会很脆弱,因为我正在构建一个包提供的东西?也就是说,在这种情况下,唯一真正的解决方案是编码全部我想要的符号?(或者 forktikzsymbols
的代码,然后在我的代码副本上构建,这当然不会受到未来对原始包所做的更改的影响。)
答案1
Tikzpeople
软件包提供了evil
转换good
为圣人或魔鬼对应符号的选项。以下是一些示例:
\documentclass{standalone}
\usepackage{tikzpeople}
\begin{document}
\begin{tikzpicture}[every node/.style={minimum width=1.5cm}]
\foreach \i [count=\ni] in {priest, nun, judge}
{
\node[\i] (\i) at (0,-2.5*\ni) {};
\node[\i, evil] (\i-evil) at (2,-2.5*\ni) {};
\node[\i, good] (\i-saint) at (4,-2.5*\ni) {};
}
\end{tikzpicture}
\end{document}
答案2
该语法可能pic
提供了一种相当简单的方法:
\documentclass[varwidth, border=5]{standalone}
\usepackage{tikz}
\tikzset{symbols/.cd,
smiley/.pic={
\draw circle [radius=1/2] (225:1/3) arc (225:315:1/3)
(135:1/4) circle [radius=1/32] (45:1/4) circle [radius=1/32];
}
}
\newcommand\tikzsymbol[2][]{\tikz\pic[#1]{symbols/#2};}
\begin{document}
\tikzsymbol{smiley}
\tikzsymbol[red]{smiley}
\tikzsymbol[scale=0.5]{smiley}
\tikzsymbol[ultra thick, line cap=round]{smiley}
\tikzsymbol[xslant=.5]{smiley}
\tikzsymbol[rotate=45]{smiley}
\end{document}