How to draw the following picture in LaTeX,
I tried to use the following code but it doesn't work.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\matrix[matrix of nodes,row sep=2em] (m)
{
$N$: & 1 & 2 & 3 & 4 &\ldots &n-1 &n \\
$N'$:& 2 & 3 & 4 & 5 &\ldots &n & n+1 \\
};
\foreach \y in {1,2,3,4,n-1,n} {
\foreach \x in {2,3,4,5,n,n+1} {
\draw[<->] (m-\y-\x) -- (m-2-\x);
}
}
\end{tikzpicture}
\captionsetup{labelformat=empty}
\caption{\label{fig:f4}Figure 1.4}
\end{figure}
Best Answer
TikZ doesn't name your nodes by their contents so you can't refer to the nodes as 1,2,3,4,5,n,n+1. Rather you have to refer to them by their position, so you want the 2nd, 3rd, 4th (etc) nodes across. You also only need to iterate over the columns since you're doing one thing to each column and not doing anything on a per-row basis.
As all your nodes are actually maths, you can use
matrix of math nodes
. I also spaced out the columns a little.(I lied a little. You can get TikZ to name the nodes whatever you like. However, in this case I think that using the positions is as simple a naming scheme as any.)