标题确实没错,我想把下图中的菱形换成心形,星形换成梅花符号:
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{3d}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
\tikzset{%
end node/.style = {%
draw,
minimum size = 5pt,
inner sep = 0pt,
fill = black,
},
star end/.style = {%
star,
end node,
star point ratio = 2.25,
},
diamond end/.style = {%
diamond,
end node,
},
}
\draw (0, 0) coordinate (A)
-- ++(0, 2) coordinate (B)
node[midway, left] {$$}
-- ++(2, 0) coordinate (C)
-- ++(0, -2) coordinate (D)
-- cycle
node[midway, above] {$$};
\node[below] at (A) {};
\node[diamond end] at (A) {};
\node[above] at (B) {};
\node[star end] at (B) {};
\node[above] at (C) {};
\node[diamond end] at (C) {};
\node[below] at (D) {};
\node[star end] at (D) {};
\end{tikzpicture}
\end{document}
简单的替换
star end/.style = {%
clubsuit,
end node,
star point ratio = 2.25,
},
diamond end/.style = {%
heartsuit,
end node,
似乎不起作用。我该如何改变钻石和心, 和星星和俱乐部这段代码中有什么问题吗?非常感谢您的帮助!
答案1
符号在pifont
包装内。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{pifont}% added <<<<<<<<<<<<<
\begin{document}
\begin{tikzpicture}
\draw (0, 0) coordinate (A) -- ++(0, 2) coordinate (B)
node[midway, left] {$$} -- ++(2, 0) coordinate (C) -- ++(0, -2) coordinate (D)
-- cycle
node[midway, above] {$$};
\node at (A) {\color{red}\ding{170}};
\node at (B) {\ding{168}};
\node at (C) {\color{red}\ding{170}};
\node at (D) {\ding{168}};
\end{tikzpicture}
\end{document}
答案2
该shapes
库不包含红心或梅花的节点形状,但您可以设计自己的节点形状:
\documentclass[tikz]{standalone}
\pgfdeclareshape{heart}{
\anchor{center}{\pgfpointorigin}
\anchor{text}
{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
\foregroundpath{
\pgfpathmoveto{\pgfpointadd{\pgfpoint{-1}{1}}{\pgfpointpolar{210}{1}}}
\pgfpatharc{210}{0}{1}
\pgfpatharc{180}{-30}{1}
\pgfpathlineto{\pgfpoint{0}{-2}}
\pgfpathclose
}
}
\pgfdeclareshape{club}{
\anchor{center}{\pgfpointorigin}
\anchor{text}
{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
\foregroundpath{
\pgfpathmoveto{\pgfpointadd{\pgfpoint{1.25}{-.25}}{\pgfpointpolar{135}{.75}}}
\pgfpatharc{135}{-180}{.75}
\pgfpathlineto{\pgfpoint{.125}{-.25}}
\pgfpathlineto{\pgfpoint{.25}{-2}}
\pgfpathlineto{\pgfpoint{-.25}{-2}}
\pgfpathlineto{\pgfpoint{-.125}{-.25}}
\pgfpathlineto{\pgfpoint{-.5}{-.25}}
\pgfpatharc{360}{45}{.75}
\pgfpathlineto{\pgfpointadd{\pgfpoint{0}{1.25}}{\pgfpointpolar{235}{.75}}}
\pgfpatharc{235}{-55}{.75}
\pgfpathclose
}
}
% \usetikzlibrary{shapes.geometric}
% \usetikzlibrary{3d}
% \usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
\tikzset{%
end node/.style = {%
draw,
minimum size = 5pt,
inner sep = 0pt,
fill = black,
},
club end/.style = {%
club,
end node,
},
heart end/.style = {%
heart,
end node,
},
}
\draw (0, 0) coordinate (A)
-- ++(0, 2) coordinate (B)
node[midway, left] {}
-- ++(2, 0) coordinate (C)
-- ++(0, -2) coordinate (D)
-- cycle
node[midway, above] {};
\node[below] at (A) {};
\node[heart end] at (A) {};
\node[above] at (B) {};
\node[club end] at (B) {};
\node[above] at (C) {};
\node[heart end] at (C) {};
\node[below] at (D) {};
\node[club end] at (D) {};
\end{tikzpicture}
\end{document}