4

I have two scopes and I want to draw an arrow from one to the other.

enter image description here

I want the red arrow to be horizontal and not oblique as it is now.

It is oblique because the node n is "lower" than that of node m and thus it expands in the vertical dimension.

Does anyone have a suggestion for how to make the red arrow horizontal?

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
  \node [anchor=base east] (m) {m};
  \filldraw (0,0) circle (1pt);
  \draw (0,0) rectangle (3,2);
\end{scope}
\begin{scope}[local bounding box=scope2,shift={(scope1.base east)},xshift=2cm]
    \filldraw (0,0) circle (1pt);
  \draw (0,0) rectangle (4,2);
  \node [anchor=north] (n) {n};
\end{scope}
 \draw [->,red] (scope1.east) -- (scope2.west);
\end{tikzpicture}

\end{document}
1
  • that's great - as my comments are no longer relevant then I will delete them to avoid confusion for others reading this Apr 16, 2023 at 11:57

2 Answers 2

4

Like this:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
  \node [anchor=base east] (m) {m};
  \filldraw (0,0) circle (1pt);
  \draw (0,0) rectangle (3,2);
\end{scope}
\begin{scope}[local bounding box=scope2,shift={(scope1.base east)},xshift=2cm]
    \filldraw (0,0) circle (1pt);
  \draw (0,0) rectangle (4,2);
  \node [anchor=north] (n) {n};
\end{scope}
 \draw [->,red] (scope1.east) -- (scope1.east -| scope2.west);
\end{tikzpicture}

\end{document}

enter image description here

Addendum:

  • it is not entirely clear the propose of use scope environments
  • code for obtained image is simpler to obtain without their use and use nodes instead of drawing rectangles:
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 0mm and 20mm,
   dot/.style = {circle, fill, inner sep=2pt, label=#1},
     N/.style = {rectangle, draw, minimum height=20mm, minimum width=30mm}
                    ]
\node [N,anchor=base east] (m) {};
\node [dot=left:$m$] at (m.south west) {};
%
\node [N,right=of m] (n) {};
\node [dot=below:$n$] at (n.south west) {};
%
\draw [-Straight Barb,red] (m) -- (n);
    \end{tikzpicture}
\end{document}

enter image description here

Now arrow not has a gap before second rectangle. If it should be, just page arrow shorter. For example:

\draw [-Straight Barb,red, shorten >=5pt] (m) -- (n);
3
  • I think you should merge your "little" modification with the solution proposed by Raffaele Santoro.
    – projetmbc
    Apr 16, 2023 at 8:32
  • 1
    @projetmbc, why? Anyway, This image I would draw as I show in addendum.
    – Zarko
    Apr 16, 2023 at 8:39
  • As you want... ;-)
    – projetmbc
    Apr 16, 2023 at 11:51
4

Like this:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    
    \begin{tikzpicture}
        \begin{scope}[local bounding box=scope1]
            \node [anchor=base east] (m) {m};
            \filldraw (0,0) circle (1pt);
            \draw (0,0) rectangle (3,2);
        \end{scope}
        \begin{scope}[local bounding box=scope2,shift={(scope1.base east)},xshift=2cm]
            \filldraw (0,0) circle (1pt);
            \draw (0,0) rectangle (4,2);
            \node [anchor=base west] (n) {n};
        \end{scope}
        \draw [->,red] (scope1.east) -- (scope2.west);
    \end{tikzpicture}
    
\end{document}

Output:

enter image description here

1
  • No. I want to position the n as it is in my case with anchor=north and still have a horizontal arrow.
    – tush
    Apr 16, 2023 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .