I would like to connect the anchors of a node (north + south, east + west) by a line. An easy task, but I need to do it within the node definition itself, not by an additional drawing command like in my example below. I think it should be possible, e.g. with postactions or decorations, but I am stuck on how to use them on nodes. Any ideas?
MWE #1
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw, minimum width = 1cm, minimum height = 0.5cm] (N) at (3,0) {};
\draw (0,0) -- (N) -- (6,0);
% I want to put the following within the node defintion
\draw (N.west) -- (N.east);
\end{tikzpicture}
\end{document}
MWE #2
Imagine I want to draw this polygon only by drawing nodes.
\documentclass{article}
\usepackage{tikz}
\tikzset{squarebox/.style={minimum width = 1cm, minimum height = 1cm}}
\begin{document}
\begin{tikzpicture}
\node[squarebox] (WE) at (2cm,3cm) {}; % West-East-Node
\node[squarebox] (NE) at (3cm,3cm) {}; % North-East-Node
\node[squarebox] (NS) at (3cm,2cm) {}; % North-South-Node
\node[squarebox] (ES) at (3cm,1cm) {}; % East-South-Node
\node[squarebox] (EW) at (2cm,1cm) {}; % East-East-Node
\node[squarebox] (SW) at (1cm,1cm) {}; % South-West-Node
\node[squarebox] (SN) at (1cm,2cm) {}; % South-North-Node
\node[squarebox] (WN) at (1cm,3cm) {}; % West-North-Node
% I want to put the following within the node defintions
\draw (WE.east) -- (WE.west);
\draw (NE.west) -- (NE.south);
\draw (NS.north) -- (NS.south);
\draw (ES.north) -- (ES.west);
\draw (EW.east) -- (EW.west);
\draw (SW.east) -- (SW.north);
\draw (SN.south) -- (SN.north);
\draw (WN.south) -- (WN.east);
\end{tikzpicture}
\end{document}
Remark #1: I actually don't want to draw the box. Just the line, and use the anchors.
Remark #2: I know I can declare shapes with \pgfdeclareshape{}
, which would be my next try. But it appeas to be overkill.
Thank you very much!
\draw (N.west) -- (N.east);
and make part of the node definition instead. Imagine that I finally want to connect line segments, which are actually nodes with a fixed width and height, over their anchors.