如何将第一个节点放置在投影仪中的特定位置?
我有以下代码:
\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=of base] (I) {$X_1$};
\node [circ, below left=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}
我得到:
作为第二张幻灯片。我想将 Y1 移到更靠右的位置。但是,无论我对第一行中的 (0,2.75) 做什么,似乎都没有什么区别。
如何将 Y1(以及由 Y1 决定的 Y2)进一步向右移动?我不想移动整个图形,而是将第一个节点进一步向右移动。
答案1
一旦完成,每个都tikzpicture
被视为一个盒子。节点的坐标对于测量它们之间的距离和计算大小很重要。
但是如果你想在和左节点之间绘制更大的距离Y1
,Y2
你必须更改above left
参数。默认情况下距离是1cm
,但你可以决定你想要的任何距离。
\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}