5

I want to add styles to my nodes that draw additional paths inside of the node.

For example (without proper placement of nodes)

\node[draw,circle,lVert] {};
\node[draw,circle,lHor]  {};
\node[draw,circle,lVert,lHor] {};

shall result in these nodes:

enter image description here

Keywords

strike through node, line in node, strike through style, cross, path as style

2

2 Answers 2

6

Adapting the solution of the following question (thanks to Claudio's comment): Creating a seamless XOR symbol as node

I ended up with this working and extremely simple code:

\begin{tikzpicture}[
    every node/.style={draw,circle},
    hVert/.style={append after command={(\tikzlastnode.north) edge (\tikzlastnode.south)}},
    hHorz/.style={append after command={(\tikzlastnode.west) edge (\tikzlastnode.east)}}
  ]
  \node[hVert] (a) {};
  \node[right=of a,hVert,hHorz] (f) {};
  \node[right=of f,hHorz] (b) {};
\end{tikzpicture}
3

Another option: declare three new shapes.

It would be better to declare only one new shape with some parameter to draw horizontal, vertical or both lines, but I don't know how to do it.

\documentclass[tikz, border=2mm]{standalone}

\makeatletter
\pgfdeclareshape{hVert}
{
  \inheritsavedanchors[from=circle] % this is nearly a circle
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \inheritbackgroundpath[from=circle]
  \foregroundpath{
    \centerpoint% 
    \pgf@xc=\pgf@x% 
    \pgf@yc=\pgf@y%
    \pgfutil@tempdima=\radius%
    \advance\pgfutil@tempdima by -.5\pgflinewidth%
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0pt}{\pgfutil@tempdima}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0pt}{-\pgfutil@tempdima}}}
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{}
  }
}
\pgfdeclareshape{hHorz}
{
  \inheritsavedanchors[from=circle] % this is nearly a circle
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \inheritbackgroundpath[from=circle]
  \foregroundpath{
    \centerpoint% 
    \pgf@xc=\pgf@x% 
    \pgf@yc=\pgf@y%
    \pgfutil@tempdima=\radius%
    \advance\pgfutil@tempdima by -.5\pgflinewidth%
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-\pgfutil@tempdima}{0pt}}}
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{}
  }
}
\pgfdeclareshape{hVertHorz}
{
  \inheritsavedanchors[from=circle] % this is nearly a circle
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \inheritbackgroundpath[from=circle]
  \foregroundpath{
    \centerpoint% 
    \pgf@xc=\pgf@x% 
    \pgf@yc=\pgf@y%
    \pgfutil@tempdima=\radius%
    \advance\pgfutil@tempdima by -.5\pgflinewidth%
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0pt}{\pgfutil@tempdima}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0pt}{-\pgfutil@tempdima}}}
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-\pgfutil@tempdima}{0pt}}}
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node[hHorz,draw, thick, blue, fill=red!30] (A) at (0,0) {};
\node[hVert,draw, red, fill=blue!30, minimum size=.75cm] (B) at (1,1) {};
\node[hVertHorz,draw, thick,fill=red!30!blue] (C) at (2,0) {};
\draw (A)--(B)--(C);
\end{tikzpicture}

\end{document}

enter image description here

1
  • I thought about this. But I'm going to require even more decorations and the number of shapes would grow exponentially. Also I need to decorate both circles and squares. But maybe this solution serves someone else.
    – ziggystar
    Feb 13, 2014 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.