# Displaying prime number differences

I am trying to make several nodes in my project like this:

 \Tree [.S This [.VP ] ]


I have searched with no results. I want something like • What you have (blurrily) shown is not a tree, and I don't think that tree drawing packages will help you here. The TikZ graphs library might be much more appropriate. What exactly is the image you've tried to show us? What is it for or what does it represent? Can you find a better image? – Alan Munn May 19 '15 at 1:10
• Sorry about that, i am finding the number between each prime number and i wanted to draw them in tex one by one... like say it took 1+2 = 3 3+2 = 5 the next prime number 5+2 = 7 the next like that to 100, i just need a sample of two horizontal nodes and i will be okay to do it on my own. Thank you. – Leouret May 19 '15 at 2:27
• I've returned the question to its earlier form with your picture, otherwise your question has basically no content whatsoever. If you want to edit your question with a better picture, or with a more detailed description of what you wanted, that would be fine, but please don't delete it. – Alan Munn May 19 '15 at 16:35

Here's one way to do what you want. I've adapted the code from this answer: Produce a list of prime numbers to draw the differences between each pair of primes in the way your drawing showed.

The command will draw the differences between the primes putting 13 primes per row by default. This can be changed, as can the vertical space each row takes up.

If the first prime is not 2, then you will need to supply the value of its previous prime to draw the first node. This prime is given by the optional argument of the macro.

\documentclass[]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcounter{primecount}
\newlength{\yoffset}
\newcounter{rownum}
% command to draw the primes between two numbers and their differences
% the optional argument specifies the number of the first previous prime
% the default is 2, in which case nothing is shown; otherwise a node with
% that prime is drawn
\newcommand{\primes}{%
\setlength{\yoffset}{.75in} % vertical offset per row
\def\displaynum{13} % number of primes per row
\setcounter{rownum}{0}
\setcounter{primecount}{1}
\def\prevprime{#1}
\ifnum\prevprime=2
\node at (-1,0) (\prevprime) {};
\else
\node (\prevprime) {\prevprime};
\fi
\foreach\numb in {#2,...,#3}{%
\pgfmathisprime{\numb}%
\ifnum\pgfmathresult=1
\pgfmathparse{int(mod(\value{primecount},\displaynum))}
\ifnum\pgfmathresult=0
\stepcounter{rownum}
\node at (0,-\value{rownum}*\yoffset) (\prevprime) {\prevprime};
\setcounter{primecount}{1}
\fi
\node[right of=\prevprime,inner sep=2pt] (\numb) {\numb};
\pgfmathparse{int(\numb-\prevprime)}
\def\diff{\pgfmathresult}
\ifnum\diff=0
\setcounter{primecount}{0}
\else
\coordinate (C) at ($(\prevprime)!0.5!(\numb)$);
\node[ below of= C,inner sep=2pt ] (\diff) {\diff};
\draw (\prevprime) -- (\diff) -- (\numb);
\fi
\global\edef\prevprime{\numb}
\stepcounter{primecount}
\fi%
}%
}

\begin{document}
\begin{tikzpicture}
\primes{1}{200}
\end{tikzpicture}

\end{document} 