我想使用乳胶中的 tikz 绘制一个图形和一些表情符号,如下图所示。
NB:我在 beamer 中做一个演示,图片的意思是三角形代理在选择相应的圆形产品时感到高兴。
我发现这个问题可以给我一点帮助,但不是完全的。如何在乳胶中绘制一组小的二分图?
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{marvosym}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\newcommand{\smiley}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw (-145:0.9mm) arc (-120:-60:1.5mm);
}
}
\newcommand{\frownie}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw (-145:0.9mm) arc (120:60:1.5mm);
}
}
\newcommand{\neutranie}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw (-135:0.9mm) -- (-45:0.9mm);
}
}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}
%
\makeatletter
\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\makeatother
%
\tikzset{>=stealth',every on chain/.append style={join},
every join/.style={->}}
\tikzstyle{labeled}=[execute at begin node=$\scriptstyle,
execute at end node=$]
%
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=3em, column sep=3em]
{ \smiley\; A1 & A2 \\
\smiley\; B1 & B2 \\
\neutranie\; C1 & C2 \\
};
{ [start chain] \chainin (m-1-1);
\chainin (m-1-2);
}
{ [start chain] \chainin (m-2-1);
\chainin (m-2-2);
}
\end{tikzpicture}
\end{document}
我得到了这张照片:
答案1
我不确定这是你想要的。也许你可以只在某些情况下自动绘制箭头,但如果你需要这样做一次,那就不值得了。
一些说明:
arrows
已弃用,请使用arrows.meta
。箭头尖的定义也已更改。检查Tikz 手册(v 3.0.0)。- 最好使用
\tikzset
,\tikzstyle
看看问题应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式? - 您不需要链,您可以使用矩阵的名称以及行和列来引用矩阵的元素。例如,如果您的矩阵名为
(m)
,则您可以通过说 来引用第一列和第二行中的“单元格”(m-2-1)
。
输出
代码
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{marvosym}
\usetikzlibrary{arrows.meta,chains,matrix,positioning,scopes}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\newcommand{\smiley}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw[-] (-145:0.9mm) arc (-120:-60:1.5mm);
}
}
\newcommand{\frownie}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw[-] (-145:0.9mm) arc (120:60:1.5mm);
}
}
\newcommand{\neutranie}{\tikz[baseline=-0.75ex,black]{
\draw circle (2mm);
\node[fill,circle,inner sep=0.5pt] (left eye) at (135:0.8mm) {};
\node[fill,circle,inner sep=0.5pt] (right eye) at (45:0.8mm) {};
\draw[-] (-135:0.9mm) -- (-45:0.9mm);
}
}
\newcommand{\mytri}{\tikz[baseline=.2em,black]{
\draw[fill=white] (0,0) --++ (8pt,0) --++ (-4pt,10pt) -- cycle;
}
}
\newcommand{\mycir}{\tikz[baseline=-0.75ex,black]{
\draw[fill=white] circle (2mm);
}
}
\begin{document}
\begin{tikzpicture}[->, >={Stealth[round]}]
\matrix (m) [matrix of math nodes,row sep=1em, column sep=2em]
{
\smiley\; \mytri & \mycir & \smiley\; \mytri & \mycir \\
\frownie\; \mytri & \mycir & \neutranie\; \mytri & \mycir \\
\neutranie\; \mytri & \mycir & \frownie\; \mytri & \mycir \\
};
\draw (m-1-1) -- (m-1-2);
\draw (m-2-1) -- (m-2-2);
\draw (m-1-3) -- (m-1-4);
\draw (m-3-3) -- (m-3-4);
\end{tikzpicture}
\end{document}