我想画两个图标(药丸和胶囊),并且这些图标可以重复和调整大小。
最少的工作代码来自如何在 Latex 中画一滴水?:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\droplet}{%
\begin{tikzpicture}
\coordinate (a) at (0,1.5);% Change 1.5 to change the shape of the droplet
\node [circle,draw,fill=blue,blue] (c) at (0,0) [minimum size=40pt] {$c$};
\draw[blue,fill] (a) -- (tangent cs:node=c,point={(a)},solution=1) --
(c.center) -- (tangent cs:node=c,point={(a)},solution=2) -- cycle;
\end{tikzpicture}%
}
\begin{document}
\droplet \quad \droplet
\end{document}
两个图标可以在一起或单独出现,并可重复和调整大小。
答案1
下面有一些(希望)不言自明的 pgfkey,它们控制其尺寸,以便更容易缩放它们。请勿在饮酒时或在操作重型机械时服用它们。;-)
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{00}
\begin{tikzpicture}[rotate=-45,tdplot_main_coords,pill radius/.initial=1,
pill length/.initial=3]
\draw[top color=red!10,bottom color=red!80!black,middle color=red,shading angle=90-45]
plot[variable=\x,domain=\tdplotmainphi:\tdplotmainphi-180]
({\pgfkeysvalueof{/tikz/pill radius}*cos(\x)},{\pgfkeysvalueof{/tikz/pill radius}*sin(\x)},0)
-- plot[variable=\x,domain=\tdplotmainphi-180:\tdplotmainphi]
({\pgfkeysvalueof{/tikz/pill radius}*cos(\x)},{\pgfkeysvalueof{/tikz/pill radius}*sin(\x)},
{-(\pgfkeysvalueof{/tikz/pill length}-\pgfkeysvalueof{/tikz/pill radius})+\pgfkeysvalueof{/tikz/pill radius}*sin(\x)}) -- cycle;
\draw[top color=blue!10,bottom color=blue!80!black,middle color=blue,
shading angle=90-45]
plot[variable=\x,domain=\tdplotmainphi:\tdplotmainphi-180]
({\pgfkeysvalueof{/tikz/pill radius}*cos(\x)},{\pgfkeysvalueof{/tikz/pill radius}*sin(\x)},0)
-- plot[variable=\x,domain=\tdplotmainphi-180:\tdplotmainphi]
({\pgfkeysvalueof{/tikz/pill radius}*cos(\x)},{\pgfkeysvalueof{/tikz/pill radius}*sin(-\x)},
{(\pgfkeysvalueof{/tikz/pill length}-\pgfkeysvalueof{/tikz/pill radius})-\pgfkeysvalueof{/tikz/pill radius}*sin(\x)}) -- cycle;
\end{tikzpicture}\quad
\begin{tikzpicture}[gap width/.initial=1mm,diameter/.initial=1cm]
\fill[blue!20] (45:\pgfkeysvalueof{/tikz/diameter})
arc(45:225:\pgfkeysvalueof{/tikz/diameter}) --
cycle;
\fill[blue!50] (45:\pgfkeysvalueof{/tikz/diameter})
arc(45:-135:\pgfkeysvalueof{/tikz/diameter}) --
cycle;
\fill[blue!30] (0,0)
circle[radius=\pgfkeysvalueof{/tikz/diameter}-\pgfkeysvalueof{/tikz/gap width}];
\fill[blue!50] (45:\pgfkeysvalueof{/tikz/diameter}) --
++ ({-sqrt(2)*\pgfkeysvalueof{/tikz/gap width}},0) --
++ (-135:{2*\pgfkeysvalueof{/tikz/diameter}-2*\pgfkeysvalueof{/tikz/gap width}})
-- (225:\pgfkeysvalueof{/tikz/diameter}) -- cycle;
\fill[blue!20] (45:\pgfkeysvalueof{/tikz/diameter}) --
++ (0,{-sqrt(2)*\pgfkeysvalueof{/tikz/gap width}}) --
++ (-135:{2*\pgfkeysvalueof{/tikz/diameter}-2*\pgfkeysvalueof{/tikz/gap width}})
-- (225:\pgfkeysvalueof{/tikz/diameter}) -- cycle;
\end{tikzpicture}
\end{document}