tikz 钻石仅填充上半部分

tikz 钻石仅填充上半部分

我正在尝试使用 tikz 制作一个钻石,其中只有上半部分是填充的。这是我尝试制作的形式:

在此处输入图片描述`

在以下 MWE 中,我找不到制作 GlcA 表格的可能性。如何在以下代码中用蓝色填充上半部分?

\documentclass[border=3.14mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{angles,
                quotes,
                calc,
                positioning,
                shapes,
                arrows}

\newcommand{\GlcNAc}{\raisebox{-0.5pt}{\tikz{\node[draw,line width=0.3mm, scale=0.7, regular polygon, regular polygon sides=4, fill=blue](){};}}}

\newcommand{\GlcN}{\raisebox{-0.1pt}{
    \tikz{
      \draw[path picture={\fill[blue] (path picture bounding box.north west) -- (path picture bounding box.south east) |-cycle;},line width=0.3mm, scale=1.08] (0mm,0mm) rectangle  ++ (2mm,2mm) (0mm,2mm) -- (2mm,0mm)
    }}} 

\newcommand{\GlcA}{\raisebox{-1.3pt}{
    \tikz{
        \node[draw, line width=0.3mm, scale=0.6, diamond, fill=white](cross diamond){};
        \draw[line width=0.3mm] (cross diamond.west)--(cross diamond.east);
        % How to fill the top half in blue?
    }}}

\begin{document}

\GlcNAc
\GlcN
\GlcA

\end{document}

答案1

path picture已经在使用了,您也可以将其用于最后一个节点。\raisebox我会使用baselinekey 来代替所有这些 es。

\documentclass[border=3.14mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}


\newcommand{\GlcNAc}{%
    \tikz[baseline={([yshift=0.3mm]square.south)}]{\node[draw,
        fill=blue,line width=0.3mm,minimum size=2mm](square){};
    }} 

\newcommand{\GlcN}{%
    \tikz[baseline={([yshift=0.3mm]square.south)}]{\node[draw,path picture={\fill[blue] 
      (path picture bounding box.north west) 
      -- (path picture bounding box.south east) |-cycle;},
      line width=0.3mm,minimum size=2mm](square){};
    }} 

\newcommand{\GlcA}{\tikz[baseline={([yshift=0.3mm]cross diamond.south)}]{
        \node[draw, line width=0.3mm, scale=0.6, diamond,
        path picture={\fill[blue] (path picture bounding box.north west) 
        rectangle (path picture bounding box.east);
        \draw  (path picture bounding box.west) -- (path picture bounding box.east);}
        ](cross diamond){};
    }}

\begin{document}

\GlcNAc\
\GlcN\
\GlcA

\end{document}

在此处输入图片描述

相关内容