3

The title is indeed correct. I want to change the diamond in the following figure with heart and star with club symbol:

  \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}

The simple replacement

star end/.style = {%
                    clubsuit,
                    end node,
                    star point ratio = 2.25,
                },
                diamond end/.style = {%
                      heartsuit,
                    end node,

does not seem to work. How can I change diamond with heart, and star with club in this code? Would appreciate the help!

2 Answers 2

9

The symbols are in the pifont package.

a

\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}

pifont quick reference

3

The shapes library does not contain node shapes for hearts or clubs, but you can design your own node 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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .