Skip to content

Instantly share code, notes, and snippets.

@Sharpie
Created August 6, 2010 21:07
Show Gist options
  • Save Sharpie/512000 to your computer and use it in GitHub Desktop.
Save Sharpie/512000 to your computer and use it in GitHub Desktop.
Example showing various styles of relative positioning with TikZ.
\documentclass{minimal}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (5,0) node[above]{Hello, world!};
\end{tikzpicture}
\end{document}
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\begin{document}
\begin{tikzpicture}[
Name/.style = {font={\bfseries}}
]
\coordinate (A) at (0,0);
% ^---- A name for the node/coordinate
\coordinate (B) at (5,1);
\coordinate (C) at (3,4);
\draw (A) -- (B) -- (C) -- cycle;
\node (A-label) [left=1ex of A, Name] {A};
\node (B-label) [right=1ex of B, Name] {B};
\node (C-label) [above=1ex of C, Name] {C};
\node [above left = 2 em of C] {This is a relatively positioned node!}
edge[out=270,in=180,thick,->] (C-label);
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment