0

Is it possible to align a corner of a finite-sided node like rectangle with the center of another node.

I am using a circle and a rectangle as an example in following code. Red filled rectangle in following figure is the desired location that I did manually. Using "right=of " option is giving me a shifted node

OUTPUT: enter image description here

\begin{tikzpicture}
[node distance = 0mm]

% Gridline
\draw [step=0.5cm,gray,very thin] (-4,-4) grid (4,4);
\node (ref1) [circle,red,fill=red,minimum size=1mm] at (-3.5,3.5) {};

% BackGround Box
\node (BG1) at (-4,3.5) [draw=red, fill=red!10, thick,minimum width=3cm,minimum height=7cm, xshift=2cm, yshift=-3.5cm] {};

% Position using relative locationing
\node (BG1) [draw=black, fill=none, thick,minimum width=3cm,minimum height=7cm, right=of ref1.east,anchor=north west] {};

\end{tikzpicture}

I am looking for a generalized solution that allows aligning two nodes relative to their centers, corners

0

According to the manual (page 51), using at (coordinate) is a general approach that will "always work." It does not require the positioning library.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
[node distance = 0mm]

% Gridline
\draw [step=0.5cm,gray,very thin] (-4,-4) grid (4,4);
\node (ref1) [circle,red,fill=red,minimum size=1mm] at (-3.5,3.5) {};

% BackGround Box
\node (BG1) at (-4,3.5) [draw=red, fill=red!10, thick,minimum width=3cm,minimum height=7cm, xshift=2cm, yshift=-3.5cm] {};

% Position using relative locationing
\node (BG1) [draw=black, fill=none, thick,minimum width=3cm,minimum height=7cm,anchor=north west] at (ref1.east) {};

\end{tikzpicture}
\end{document}

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.