1

I am using the following TeX code to draw 3 shapes using Tikz library.

\documentclass[a4]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

\begin{document}
\begin{tikzpicture}
    \node[draw=red,ellipse,minimum height=1.2cm,minimum width=4cm,xshift=7cm,yshift=1cm] (q1) {};
    \node[draw=red,ellipse,minimum height=1.2cm,minimum width=4cm,xshift=7cm,yshift=-1cm] (q2) {};

    \node[circle,draw,minimum size=.5cm] (c1) {};
\end{tikzpicture}
\end{document}

The problem is to position the circle shape exactly in the mid of 2 ellipses,but 2cm to the left.

1

You can use the syntax of the calc library to do this. However, if the point is to place the node between the left ends of the ellipses, something like

\path (q1.west) -- node[circle,draw,minimum size=.5cm] (c1) {} (q2.west);

would be better I think.

In the code below I also added a third way.

enter image description here

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,calc}

\begin{document}
\begin{tikzpicture}
    \node[draw=red,ellipse,minimum height=1.2cm,minimum width=4cm,xshift=7cm,yshift=1cm] (q1) {};
    \node[draw=red,ellipse,minimum height=1.2cm,minimum width=4cm,xshift=7cm,yshift=-1cm] (q2) {};

    \node[circle,draw,minimum size=.5cm] (c1) at ($(q1)!0.5!(q2) + (-2cm,0)$) {};

% place node relative to west side of ellipses
    \path (q1.west) -- node[circle,draw,minimum size=.5cm] (c1) {} (q2.west);

% A different option, same result:
    \path (q1) -- node[blue,circle,draw,minimum size=.5cm,xshift=-2cm] (c1) {} (q2);
\end{tikzpicture}
\end{document}
| improve this answer | |

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.