2

How do I place the first node at a specific position in beamer?

I have the following code:

\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}

I get:

enter image description here

as the second slide. I want to move the Y1 to be further to the right. However, no matter what I do to the (0,2.75) in the first line, it seems to make no difference.

How do I move the Y1 (and Y2, which is decided on by Y1) further to the right? I do not want to move the entire figure, but place the first node further to the right.

1 Answers1

2

Every tikzpicture is considered as a box once is finished. Coordinates for nodes are important to measure the distance between them and to compute the size.

But if you want to draw a larger distance between Y1 and Y2 and left nodes, you must change above left parameter. By default the distance is 1cm but you can decide whatever you want.

\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}

enter image description here

Ignasi
  • 136,588