Forum digitalis

3.3 Positioning

Absolute Positioning

You place elements directly in the Cartesian coordinate system.

\begin{tikzpicture} \draw (0,0) -- (2,1); \node at (-0.1,-0.1) {Start}; \node at (2.1,1.2) {Goal}; \end{tikzpicture}

Conclusion

Relative Positioning

Objects are positioned relative to others. Requirement: \usetikzlibrary{positioning} (in the preamble).

\begin{tikzpicture} \node (A) {Start}; \node[below=of A] (B) {End}; \draw (A) -- (B); \end{tikzpicture}

Conclusion

Additional Positioning

Besides absolute and relative positioning, there are other positioning options.

\begin{tikzpicture} \node (A) {Center}; \node[right=of A] (B) {Right}; \node[above=of A] (C) {Top}; \node[left=of A] (D) {Left}; \node[below=2cm of A] (E) {Further down}; \end{tikzpicture}

Combined Positioning

There is also a positioning option that combines relative and absolute positioning.

\begin{tikzpicture} \node (A) {Start}; \node[below=of A, xshift=5mm] (B) {Shifted}; \draw (A) -- (B); \end{tikzpicture}

Anchor (Alignment)

An anchor determines which point of a node is at a given position. By default, it is the center.
Syntax: \node[anchor=option] at (x,y) {Text};
Options are: center, north, south, east, west, north west, north east, south west, south east.

\begin{tikzpicture} \node[anchor=north] at (0,0) {Center}; \node[anchor=north east] at (-5,-2) {Bottom left}; \node[anchor=south west] at (2,2) {Top right}; \draw (0,0) -- (2,2); \draw (2,2) -- (-5,-2); \end{tikzpicture}

Use Cases