tikz 节点位置

tikz 节点位置

我有一个分成四个三角形的菱形,我想在每个三角形的中心写字,但定位有困难。请帮我解决这个问题。谢谢

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{wasysym}
\usetikzlibrary{shapes.geometric, calc}
\newcommand{\mydiamond}[7][]{%
  \begin{scope}[transform shape]
     \node [alias=los, diamond, draw, fill=#3, #1] (#2) {} ;

    \draw ([yshift=-0.3] los.north) -- ([yshift=0.3] los.south) ;
    \draw ([xshift=-0.3] los.east) -- ([xshift=0.3] los.west) ;


    \path [auto=false] (los.west) -- ([xshift=0.3] los.west)
          node (G) [pos=0.8] {} ;
    \path [auto=false] (los.east) -- ([xshift=-0.3] los.east)
          node (D) [pos=0.5] {} ;
   \path [auto=false] (los.north) -- ([yshift=0.3] los.north)
          node (V) [pos=0.6] {} ;
   \path [auto=false] (los.south) -- ([yshift=-0.3] los.south)
          node (U) [pos=0.3] {} ;


    \node [font=\tiny, scale=0.5] at (G) {#4} ;
      \node [font=\tiny, scale=0.5] at (D) {#5} ;
  \node [font=\tiny, scale=0.5] at (V) {#6} ;
\node [font=\tiny, scale=0.5] at (U) {#7} ;
\end{scope}

}%
\begin{document}

\begin{tikzpicture}[scale=5, auto]
\mydiamond{init}{green!10}{$\CIRCLE$}{\tiny{$\CIRCLE$$\CIRCLE$}}{3}{4}
\end{tikzpicture}

\end{document} 

答案1

重心坐标系在这里很有用。

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{wasysym}
\usetikzlibrary{shapes.geometric, calc}
\newcommand{\mydiamond}[7][]{%
\begin{scope}[transform shape]
   \node [alias=los, diamond, draw, fill=#3, #1] (#2) {} ;

   \draw ([yshift=-0.3] los.north) -- ([yshift=0.3] los.south) ;
   \draw ([xshift=-0.3] los.east) -- ([xshift=0.3] los.west) ;

   \coordinate (n) at (los.north);
   \coordinate (s) at (los.south);
   \coordinate (w) at (los.west);
   \coordinate (e) at (los.east);
   \coordinate (c) at (los.center);

   \coordinate (G) at (barycentric cs:n=1,c=1,w=1);
   \coordinate (D) at (barycentric cs:s=1,c=1,w=1);
   \coordinate (V) at (barycentric cs:n=1,c=1,e=1);
   \coordinate (U) at (barycentric cs:s=1,c=1,e=1);


    \node [font=\tiny, scale=0.5] at (G) {#4} ;
    \node [font=\tiny, scale=0.5] at (D) {#5} ;
    \node [font=\tiny, scale=0.5] at (V) {#6} ;
    \node [font=\tiny, scale=0.5] at (U) {#7} ;
\end{scope}
}%
\begin{document}

\begin{tikzpicture}[scale=5, auto]
\mydiamond[minimum size=1cm]{init}{green!10}{$\CIRCLE$}{\tiny{$\CIRCLE\CIRCLE$}}{3}{4}
\end{tikzpicture}

\end{document} 

在此处输入图片描述

相关内容