# How to draw the following picture in LaTeX?

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}
• Tip for the future: you could expand a little on "it doesn't work" to give answerers a hint as to what they might expect to see when they try your code. "It doesn't work" could mean anything from "the arrows go to the wrong places" to "my computer overheated and I had to call the fire brigade". – Loop Space Apr 11 '16 at 13:57
• I was going to try to learn LaTeX (downloaded it and everything), but my brain hurts just from reading this, so I'm guessing it takes a lot more smarts than I have handy. How disappointing. But good to know before I jump into it. – Shalryn Apr 11 '16 at 17:59
• @Shalryn well, I'd hope it would be clear that reading this question is not a good way to learn LaTeX! It's a complicated system but there are a number of good manuals out there. See this question for some pointers. – David Z Apr 12 '16 at 6:04
• Am I mistaken or the \label should go after the \caption command, and not inside it? – Bakuriu Apr 12 '16 at 11:06

## 4 Answers

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.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/303682/86}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}
\matrix[matrix of math nodes,row sep=1cm,column sep=.5cm] (m)
{
N: & 1      & 2      & 3      & 4  &\ldots          &n-1   &n     \\
N':& 2       & 3      & 4      & 5  &\ldots          &n     & n+1 \\
};
\foreach \x in {2,3,4,5,7,8} {
\draw[<->] (m-1-\x) -- (m-2-\x);
}
\end{tikzpicture}
\end{document}

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.)

If a non-tikz solution is fine you can use simply a matrix

\documentclass{article}

\usepackage{amsmath} % defines matrix

\begin{document}

${ \addtolength{\arraycolsep}{.5em} \begin{matrix} N\colon & 1 & 2 & 3 & 4 & \dots & n-1 & n & \dots \\ & \updownarrow & \updownarrow & \updownarrow & \updownarrow & & \updownarrow & \updownarrow \\ N'\colon & 2 & 3 & 4 & 5 & \dots & n & n+1 & \dots \\ \end{matrix}}$

\end{document}

The width of the matrix columns (\arraycolsep) has been slightly increased, otherwise the result would have been too tight. The grouping {...} restricts the redefinition of \arraycolsep to this matrix alone: it isn't necessary in this example, for the math mode $...$ also acts a a group, but it would be necessary if you had other matrices in the same displayed math formula.

the cells of the table should be numbered with the number of line and column, here is a solution

Please note, your source can not be compiled, the next time, proposes a minimum compilable source

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations, positioning, intersections, calc,matrix}%
\usepackage{amsmath,amssymb}
\usepackage{bodegraph}

%\usepackage{align}

\begin{document}
\begin{figure}
\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 {2,3,4,...,8} {
\draw[<->] (m-1-\y) -- (m-2-\y);
}
\end{tikzpicture}
\caption{\label{fig:f4}Figure 1.4}
\end{figure}

\end{document}

You may also use the external program ipe to draw your image as a pdf, to be included into the LaTeX file. The ipe manual is sufficient, and the software itself is pretty much self-explanatory.

I attached the output provided by ipe.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Seamus Apr 12 '16 at 8:52