4

I hope someone can help me. How can I make both ellipses have the same size?

I attach the code and an image of how I want it to look

\begin{tikzpicture}
  \node (1) at (0,0) {1};\filldraw(1.east) circle (1pt);
  \node (2) [below of = 1] {2};\filldraw(2.east) circle (1pt);
  \node (3) [below of = 2 ] {3};\filldraw(3.east) circle (1pt);
  \node (4) [below  of=  3] {4};\filldraw(4.east) circle (1pt);
  \node[fit = (1) (2) (3) (4) , ellipse, draw=blue, minimum width =2cm,thick, label=below:\(A\)]{};
 
 \node (1_1) at (3,0) {1};\filldraw(1_1.west) circle (1pt);
 \node (2_2) [below of=1_1] {2};\filldraw(2_2.west) circle (1pt);
 \node (3_3) [below of=2_2] {3};\filldraw(3_3.west) circle (1pt);
 \node[fit = (1_1) (2_2) (3_3) , ellipse, draw=blue, minimum width =2cm,thick,label=below:\(B\)]{};
 
 \draw[->, shorten >=.1cm, stealth] (1.east) to (1_1.west);
 \draw[->, shorten >=.1cm, stealth] (2.east) to (3_3.west);
 \draw[->, shorten >=.1cm, stealth] (3.east) to (2_2.west);
 \draw[->, shorten >=.1cm, stealth] (4.east) to (1_1.west);

\end{tikzpicture}

enter image description here

3
  • Welcome to TeX.SE! Seems to be equal for me ...
    – Mensch
    Apr 24, 2022 at 19:41
  • hi @Mensch Thank you. I want it to look like the picture but it looks different size Apr 24, 2022 at 19:52
  • Why don't you just draw both ellipses and place nodes inside instead of using fit? You could also use fit but declare a common minimum width and a minimum height to those ellipses.
    – SebGlav
    Apr 24, 2022 at 22:27

3 Answers 3

2

ellipses the same size

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{fit,shapes,positioning}

\begin{document}
    \begin{tikzpicture}[node distance = 8mm,ell/.style={ellipse, draw=blue,thick,minimum height=6cm, minimum width=25mm, inner sep=0pt}]
      \node (1) at (0,0) {1};\filldraw(1.east) circle (1pt);
      \node (2) [below = of 1] {2};\filldraw(2.east) circle (1pt);
      \node (3) [below = of 2 ] {3};\filldraw(3.east) circle (1pt);
      \node (4) [below = of 3] {4};\filldraw(4.east) circle (1pt);
      \node[ell,fit = (1) (2) (3) (4) ,label=below:\(A\)]{};
     
     \node (1_1) at (4,0) {1};\filldraw(1_1.west) circle (1pt);
     \node (2_2) [below = of 1_1] {2};\filldraw(2_2.west) circle (1pt);
     \node (3_3) [below = of 2_2] {3};\filldraw(3_3.west) circle (1pt);
     \node (4_4) [below = of 3_3] {\vphantom{4}};
     \node[ell,fit = (1_1) (2_2) (3_3) (4_4),label=below:\(B\)]{};
     
     \draw[->, shorten >=.1cm] (1.east) to (1_1.west);
     \draw[->, shorten >=.1cm] (2.east) to (3_3.west);
     \draw[->, shorten >=.1cm] (3.east) to (2_2.west);
     \draw[->, shorten >=.1cm] (4.east) to (1_1.west);
    
    \end{tikzpicture}
\end{document}
1
  • 1
    Thank you for taking the time to reply, your help was very helpful. Apr 27, 2022 at 23:27
2

A fit node is usually placed around the nodes it covers, but the reference nodes only define their size because the position can be whatever. This is what is shown in following code. Both ellipses are defined with the same fit collection of nodes which means that both will have equal dimensions, but the second is placed around right nodes. This way there's no need to fix a minimum height as is proposed in other solutions.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{fit, shapes.geometric, positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[> = Stealth]
  \node (1) at (0,0) {1};\filldraw(1.east) circle (1pt);
  \node (2) [below of = 1] {2};\filldraw(2.east) circle (1pt);
  \node (3) [below of = 2 ] {3};\filldraw(3.east) circle (1pt);
  \node (4) [below  of=  3] {4};\filldraw(4.east) circle (1pt);
  \node[fit = (1) (4) , ellipse, draw=blue, thick, minimum width=2cm, label=below:\(A\)] (A){};
 
 \node (1_1) at (3,-0.5) {1};\filldraw(1_1.west) circle (1pt);
 \node (2_2) [below of=1_1] {2};\filldraw(2_2.west) circle (1pt);
 \node (3_3) [below of=2_2] {3};\filldraw(3_3.west) circle (1pt);
 \node[fit = (1) (4), ellipse, draw=blue, thick, minimum width=2cm, label=below:\(B\), anchor=south] at (A.south-|1_1){};
 
 \draw[->, shorten >=.1cm] (1.east) to (1_1.west);
 \draw[->, shorten >=.1cm] (2.east) to (3_3.west);
 \draw[->, shorten >=.1cm] (3.east) to (2_2.west);
 \draw[->, shorten >=.1cm] (4.east) to (1_1.west);

\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you very much for the help, I did not know that fit properties, I spent a lot of time looking for other solutions. very grateful for your help Apr 27, 2022 at 23:22
2
  • Sizes of the both ellipse are already the same. Eventually it can be slightly reduced (as is done in MWE below).
  • It is sensible to define common styles of for all image elements
  • Using the chains library make image code a bit shorter
\documentclass[tikz,border=3.141592]{standalone}
\usetikzlibrary{arrows.meta,
                calc, chains, 
                fit,
                positioning,
                shapes}

\begin{document}
    \begin{tikzpicture}[
node distance = 8mm and 32mm,
  start chain = A going below,
  start chain = B going below,
   arr/.style = {draw, -Stealth}, 
   dot/.style = {circle, fill, inner sep=2pt, outer sep=1pt,
                 node contents={},
                 label=#1},
   ell/.style = {ellipse, draw=blue, thick,
                 minimum height=55mm, minimum width=20mm, inner sep=0pt,
                 node contents={},
                 fit=#1}
                        ]
\foreach \i in {1,2,3,4}                    
   \node (a\i) [dot=left:\i, on chain=A];
\node[ell = (a1)(a4),label=below:$A$];
%
   \node (b1) [dot=right:1, 
               right=of $(a1)!0.5!(a2)$,
               on chain=B
               ];
\foreach \i in {2,3}
   \node (b\i) [dot=right:\i, on chain=B];
\node[ell = (b1)(b3),label=below:$B$];
%%
\draw[arr]  (a1) edge (b2)
            (a2) edge (b3)
            (a3) edge (b2)
            (a4) edge (b1);
    \end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    Thank you very much for the help, I know a little about latex, I see that I still have a lot to learn. I loved your solution. I still don't understand it much, but I must understand it to make more examples in my function classes Apr 27, 2022 at 23:19

You must log in to answer this question.

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