TikZ:如何将节点更改为椭圆并绘制弯曲箭头

TikZ:如何将节点更改为椭圆并绘制弯曲箭头

我有下面的代码,它可以给我提供该图。

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{times, pgf,verbatim} % pgf added for the umbc4 sty
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart,calc,arrows.meta}
\tikzset{
  basic/.style={draw, text centered},
  circ/.style={basic, circle, minimum size=2em, inner sep=1.5pt},
  rect/.style={basic, text width=1.5em, text height=1em, text depth=.5em},
  1 up 1 down/.style={basic, text width=1.5em, rectangle split, rectangle split horizontal=false, rectangle split parts=2},
}
\newcommand{\frt}[1]{\frametitle{#1}}
\title[]{Example}
\begin{document}
\titlepage
\begin{frame}
\frt{tikzpicture example}
\begin{tikzpicture}
  \node [rect] (base) {$Y_1$} (0,2.75);
  \node [rect, below=of base] (Y2) {$Y_2$};
  \node [circ, above left=1cm and 4cm of base] (I) {$X_1$};
  \node [circ, below left=1cm and 4cm of base] (T) {$X_5$};
  \foreach \i [count=\ino] in {X_2,X_3,X_4,X_5,X_6,X_7,X_8} \node [circ] at ($(I)!\ino/4!(T)$) (\i) {$\i$};
  \draw [->,>=Stealth] (X_3) -- (base);
  \coordinate (arr) at (base.west);
  \foreach \i/\j in {X_2/arr,X_4/arr,X_6/arr,X_7/arr,X_8/arr,I/arr,T/arr} \draw [->,>=Stealth] (\i) -- (\j);
  \draw [->,>=Stealth] (T) -- (Y2);
  \coordinate (arr) at (Y2.west);
  \foreach \i/\j in {X_2/arr,X_3/arr,X_4/arr,X_6/arr,X_7/arr,X_8/arr,I/arr} \draw [->,>=Stealth] (\i) -- (\j);
\end{tikzpicture}

\end{frame}
\end{document}

所以我得到了这幅图像。

所以,这很合理,但我希望圆圈实际上是椭圆形。此外,我还希望左侧有一个连接 X_1 和 X_5 的弯曲箭头。我该如何完成这项任务?

答案1

我简化了循环,以便迭代在单个变量上完成,因为第二个变量是常量,所以在常量上循环是没用的。

截屏

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{times, pgf,verbatim} % pgf added for the umbc4 sty
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart,calc,arrows.meta}
\usetikzlibrary{shapes.geometric}%<-- new library
\tikzset{
  basic/.style={draw, text centered},
  circ/.style={basic, ellipse, minimum height=1em,minimum width=2cm, inner sep=1.5pt},
  rect/.style={basic, text width=1.5em, text height=1em, text depth=.5em},% ellipse
  1 up 1 down/.style={basic, text width=1.5em, rectangle split, rectangle split horizontal=false, rectangle split parts=2},
}
\newcommand{\frt}[1]{\frametitle{#1}}
\title[]{Example}
\begin{document}
%\titlepage
\begin{frame}
\frt{tikzpicture example}
\begin{tikzpicture}
  \node [rect] (base) {$Y_1$} (0,2.75);
  \node [rect, below=of base] (Y2) {$Y_2$};
  \node [circ, above left=1cm and 4cm of base,alias=X_1] (I) {$X_1$};%<- add a alias X_1 for I 
  \node [circ, below left=1cm and 4cm of base,red] (T) {$X_5$};

  \foreach \i [count=\ino] in {2,...,8} \node [circ] at ($(I)!\ino/4!(T)$) (X_\i) {$X_\i$};
%  \draw [->,>=Stealth] (X_3) -- (base);
%  \coordinate (arr) at (base.west);
  \foreach \i in {1,...,8} 
    \draw [->,>=Stealth] (X_\i.0) -- (base.west);
    \draw  (X_1) to [out=180,in=180](X_5);
%  \draw [->,>=Stealth] (X_5) -- (Y2);
%  \coordinate (arr) at (Y2.west);
  \foreach \i in {1,...,8} \draw [->,>=Stealth] (X_\i.east) -- (Y2.west);
\end{tikzpicture}

\end{frame}
\end{document}

相关内容