# Tikz Nodes

October 17, 2011
By

(This article was first published on Software for Exploratory Data Analysis and Statistical Modelling, and kindly contributed to R-bloggers)

Nodes are used in tikz to place content in a picture as part of a LaTeX document.

Fast Tube by Casper

When creating a tikz picture the origin is assumed to be at (0,0) and objects are placed with positioning relative to the origin on the picture. If we wanted to add a grid with lines from -3 to +3 in both the horizontal and vertical axes then we would use the \draw command combined with grid.

\draw (-3,-3) grid (3,3);

We can use the draw options to change how the grid is displayed. To make the grid lines thin we could add very thin and change the colour to a light gray (black!20):

\draw[very thin,black!20] (-3,-3) grid (3,3);

To add a node with text we use a combination of \draw and node, For example to put the node with a single letter A at (1,1):

\draw (1,1) node {A};

We can put an outline around the text in a node by specifying a shape and the draw option (which refers to the colour of the outline of the shape).

\node[shape=rectangle,draw=black] at (0,2) {B};

The fill option is for the inside of the shape. A circle with outline and filled background could be drawn with the following code:

\node[shape=circle,draw=blue,fill=blue!50] at (2,2) {D};

Other useful resources are provided on the Supplementary Material page.

To leave a comment for the author, please follow the link and comment on his blog: Software for Exploratory Data Analysis and Statistical Modelling.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,