1

I am drawing a table with arrows in it. All the arrows are fine except for vertical ones pointing down. Here is a MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}


  \tikzset{ 
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={rectangle,text width=1.5em,align=center},
        text height=1.1ex,
        nodes in empty cells,
    },
}
\begin{tikzpicture}
    \matrix (mat) [table]{
    &&0&0\\
    &0&1&2\\
    1&1&1&2\\
    1&2&2&2\\
    1&3&3&3\\
};

\begin{scope}[shorten >=7pt,shorten <= 7pt]

\draw[->]  (mat-1-3.center) -- (mat-2-4.center);
\draw[->]  (mat-2-4.center) -- (mat-3-4.center);

\end{scope}

\end{tikzpicture}
\end{document}

The arrow pointing down is rendered in a very strange way.

enter image description here

How can I fix this?

  • You shorten your arrow by 14 pt ([shorten >=7pt,shorten <= 7pt]) but your vertical arrow is shorter than this length. – leandriis Mar 19 at 21:29
  • 1
    I changed the text height=1.1ex to text height=1.5ex and 4pt instead of 7pt in shorten option. It seems good. – ferahfeza Mar 19 at 21:30
  • 1
    With ` row sep=5pt, column sep=5pt,` and \begin{scope} \draw[->,shorten >=-7pt,shorten <= -7pt] (mat-1-3.south east) -- (mat-2-4.north west); \draw[->] (mat-2-4.south) -- (mat-3-4.north); \end{scope} you can achieve the following output: i.stack.imgur.com/Q5Mzl.png – leandriis Mar 19 at 21:37
3

Why don't you increase the space between rows?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{ 
    table/.style={
        matrix of nodes,
        row sep=3ex,
        column sep=-\pgflinewidth,
        nodes={rectangle,text width=1.5em,align=center},
        text height=1.1ex,
        nodes in empty cells,
    },
}
\begin{document}
\begin{tikzpicture}[shorten >=7pt,shorten <= 7pt]
    \matrix (mat) [table]{
    &&0&0\\
    &0&1&2\\
    1&1&1&2\\
    1&2&2&2\\
    1&3&3&3\\
};
\draw[->]  (mat-1-3.center) -- (mat-2-4.center);
\draw[->]  (mat-2-4.center) -- (mat-3-4.center);
\end{tikzpicture}
\end{document}

enter image description here

You could also use tikz-cd and simplify your code:

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
    &&0\ar[dr]&0\\
    &0&1&2\ar[d]\\
    1&1&1&2\\
    1&2&2&2\\
    1&3&3&3\\
\end{tikzcd}
\end{document}

enter image description here

Edit: it's very difficult to have a table with 27 rows and columns and also arrows.

I tried with adjustbox:

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{adjustbox}
\begin{document}
\noindent Some blind text just to show that the table is larger than text width. Blah blah

\begin{adjustbox}{width=.9\paperwidth, center}
\begin{tikzcd}[column sep=8pt,
row sep=12pt]
    1\ar[dr] &  2\ar[r] &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10\ar[r] &  11  &   12  &   13  &   14\ar[dr]   &   15  &   16\ar[d]    &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
2   &   2\ar[d] &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
3   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
4   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
5   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
6   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
7   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
8   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
9   &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
10  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
11  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
12  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
13  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
14  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
15  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
16  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
17  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
18  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
19  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
20  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
21  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
22  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
23  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
24  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
25  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
26  &   2   &   3   &   4   &   5   &   6   &   7   &   8   &   9   &   10  &   11  &   12  &   13  &   14  &   15  &   16  &   17  &   18  &   19  &   20  &   21  &   22  &   23  &   24  &   25  &   26  &   27  \\
27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  &   27  \\
\end{tikzcd}%
\end{adjustbox}
\end{document}

enter image description here

  • Thank you. The table will have many more rows and columns so I can’t afford to increase its overall size sadly. I didn’t know about tikz-cd, that looks great. – Anush Mar 20 at 7:06
  • 1
    @Anush You can also increase only one row distance, also with tikz-cd you can set row distances as you like. How many rows and columns do you have? – CarLaTeX Mar 20 at 7:13
  • 27 rows and columns. – Anush Mar 20 at 7:16
  • 1
    @Anush And have all the cells 2 digits at the maximum? I'll update my answer asap, sorry, no time at the moment. – CarLaTeX Mar 20 at 7:19
  • 2
    @Anush See my edit, indeed it's very difficult to have a so large table! If you have only few arrows, it's possible to set the distance larger only for few columns. – CarLaTeX Mar 20 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.