我想要绘制这样的图表:
一般来说,SolveMe 手机(播放部分)
我想我可以用原始代码来完成,但我想用自定义命令来完成,例如:“制作水平线”、“放置六边形节点”等等。这可能吗?
编辑 :
这是“原始代码”的答案,但它不是模块化的:
\begin{tikzpicture}[edge from parent fork down]
\node{\space}
child {node [draw, fill=green!20,rectangle] {\space}
child {node [draw, fill=green!20,rectangle] {\space}}
}
child {node [draw, fill=blue!20,circle] {\space}
child {node [draw, fill=yellow!20] {\space}}
child {node [draw, fill=red!20] {\space}}
};
\end{tikzpicture}
这与我想要的相差甚远。
答案1
(对我而言)无需使用树库就可以更轻松地绘制您的图片:
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{chains,
positioning,
shadows,
shapes.geometric
}
\begin{document}
\begin{tikzpicture}[
node distance=5mm and 11mm,
start chain = going below,
font = \sffamily,
basic/.style = {shape=regular polygon, outer sep=0pt, minimum size=1ex,
node contents={~~}, on chain},
hex/.style = {basic,regular polygon sides=6,
top color=teal!30, bottom color=teal!90},
tri/.style = {basic,regular polygon sides=3,
top color=purple!30, bottom color=purple!90,
shape border rotate=-180, inner sep=2pt},
pet/.style = {basic,regular polygon sides=5,
top color=orange!30, bottom color=orange!90},
]
\coordinate[left =of {(0,0)}] (a);
\coordinate[right=of {(0,0)}] (b);
%
\node (a1) [hex,below=of a];
\node (a2) [hex];
\node (a3) [hex];
\node (a4) [tri,below=of a3];
\node[right=0mm of a4.east] {=12};
%
\node (b1) [pet,below=of b];
\node (b2) [tri];
%
\node (c) [hex,left=of a4.west];
\node[right=0mm of c.east] {=5};
\node (d) [pet,right=of a4.east];
\node[right] at (d.east) {$=$};
\node[draw=gray,text width=2em,minimum height=4ex,
right=5 mm of d.east] {};
% lines
\draw[gray,thick] (0,0) -- + (0,7mm);
\draw[ultra thick,cap=round] (a) -- (b);
\draw[gray] (a) -- (a1) (a1) -- (a2) (a2) -- (a3)
(b) -- (b1) (b1) -- (b2);
\end{tikzpicture}
\end{document}
这里我用五边形代替心形。它可以通过 来绘制pic
,但是对于所需图像的第一个近似值,五边形就足够了:
升级:如果你非常想要心形而不是五边形,那么你可以用 画一个心形pic
。对于这些小图片,在图片中放置它需要多花点功夫:
\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{chains,
positioning,
shadows,
shapes.geometric
}
\begin{document}
\begin{tikzpicture}[
node distance=5mm and 13mm,
start chain = going below,
font = \sffamily,
basic/.style = {shape=regular polygon, outer sep=0pt, minimum size=1ex,
node contents={~~}, on chain},
hex/.style = {basic,regular polygon sides=6,
top color=teal!30, bottom color=teal!90},
tri/.style = {basic,regular polygon sides=3,
top color=purple!30, bottom color=purple!90,
shape border rotate=-180, inner sep=2pt},
pet/.pic = {\path[top color=orange!30, bottom color=orange!90]
(0,0) .. controls (0.0,0.15) and (-0.3,0.20) .. (-0.3,0.4)
arc (180:0:0.15)
arc (180:0:0.15)
.. controls (0.3,0.20) and ( 0.0,0.15) .. (0,0);
\coordinate (-south) at (0,0.02);
\coordinate (-north) at (0,0.4);
\coordinate (-west) at (-0.2,0.3);
\coordinate (-center) at (0,0.3);
\coordinate (-east) at (+0.2,0.3);}
% pet/.style = {basic,regular polygon sides=5,
% top color=orange!30, bottom color=orange!90},
]
\coordinate[left =of {(0,0)}] (a);
\coordinate[right=of {(0,0)}] (b);
%
\node (a1) [hex,below=of a];
\node (a2) [hex];
\node (a3) [hex];
\node (a4) [tri,below=of a3];
\node[right=0mm of a4.east] {=12};
%
\pic[below=of a1 -| b] (b1) {pet};
\node (b2) [tri,below=of b1-south];
%
\node (c) [hex,left=of a4.west];
\node[right=0mm of c.east] {=5};
\pic [right=17mm of a4.south] (d) {pet};
\node[right] at (d-east) {$=$};
\node[draw=gray,text width=2em,minimum height=4ex,
right=5 mm of d-east] {};
% lines
\draw[gray,thick] (0,0) -- + (0,7mm);
\draw[ultra thick,cap=round] (a) -- (b);
\draw[gray] (a) -- (a1) (a1) -- (a2) (a2) -- (a3)
(b) -- (b1-north) (b1-south) -- (b2);
\end{document}
现在的图片是:
答案2
仅使用简单的堆栈。
\documentclass{article}
\usepackage{marvosym,amssymb,txfonts,stackengine,xcolor,scalerel}
\def\hex{\kern.2pt\textcolor{green!80!black}{\scalerel*{$\Hexasteel$}{)}}}
\def\btd{\textcolor{blue!30!red}{\scalerel*{\blacktriangledown}{)}}}
\def\hrt{\textcolor{orange!80!red}{\scalerel*{\varheartsuit}{)}}}
\def\topstik{\rule{1pt}{10pt}}
\def\stik{\rule{1pt}{5pt}}
\def\hbar{\rule{2.5em}{2pt}}
\setstackgap{S}{-.2pt}
\setstackEOL{\cr}
\begin{document}
\stackunder[15pt]{%
\stackunder{\Shortstack{\topstik\cr\hbar}}{%
\Shortunderstack{\topstik\cr\hex\cr\stik\cr\hex\cr\stik\cr\hex}%
\quad%
\Shortunderstack{\topstik\cr\hrt\cr\stik\cr\btd}%
}%
}{%
$\hex=5\quad\btd=12\quad\hrt=\fbox{\strut~~~~~}$%
}
\end{document}