[Tex/LaTex] Drawing Multiple Diagonal Arrows in a Table

arraysarrowstablestikz-pgf

My question is basically the same as this one, but with many arrows instead. (I'd like to see the TikZ solution–I feel like once I get it here, I'll be able to extrapolate and do it in other cases as well…)

How do I draw diagonal southwest-pointing arrows through the following table?
I want an arrow that through x_{1}^1, an arrow that goes through x_{1}^2 AND x_{2}^1, an arrow that goes through x_{1}^3 and x_{2}^2 and x_{3}^1, an arrow that goes through x_{2}^3 and x_{3}^2, and an arrow that goes through x_{3}^3. To make the picture more clear, I want each arrow to start in the upper-right corner of the first element it goes through, and end in the lower-left corner of the last element it goes through.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
  \tikz[overlay,remember picture] \node (#1) {};}

\[
\begin{array}{*{6}{c}}
E_{1} & = & x_{1}^1 & x_{1}^2 & x_{1}^3 & ... \\
\\
E_{2} & = & x_{2}^1 & x_{2}^2 & x_{2}^3 & ... \\
\\
E_{3} & = & x_{3}^1 & x_{3}^2 & x_{3}^3 & ... \\
... \\
\end{array}
\]

\end{document}

Best Answer

You can place, for each arrow, two nodes (one to signal the start, and the other one the end) and then use a loop to connect each pair of nodes:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
  \tikz[overlay,remember picture] \node (#1) {};}

\begin{document}

\[
\begin{array}{*{6}{c}}
E_{1} & = & \tikzmark{e1}x_{1}^1\tikzmark{s1} & x_{1}^2\tikzmark{s2} & x_{1}^3\tikzmark{s3} & ... \\
\\
E_{2} & = & \tikzmark{e2}x_{2}^1 & x_{2}^2 & x_{2}^3\tikzmark{s4} & ... \\
\\
E_{3} & = & \tikzmark{e3}x_{3}^1 & \tikzmark{e4}x_{3}^2 & \tikzmark{e5}x_{3}^3\tikzmark{s5} & ... \\
... \\
\end{array}
\]
\begin{tikzpicture}[overlay,remember picture]
\foreach \i in {1,2,...,5}
  \draw[->] ($(s\i.north east)+(-0.1,0.1)$) -- ($(e\i.south west)+(0.1,0)$);
\end{tikzpicture}

\end{document}

enter image description here

As the above image shows, the lines are not parallel; to correct this, perhaps the fastest way is to use a matrix of nodes:

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

\begin{document}

\begin{tikzpicture}
\matrix[matrix of math nodes,inner sep=1pt,row sep=1em,column sep=1em] (M)
{
    E_1 & = & x_{1}^{1} & x_{1}^{2} & x_{1}^{3}  & \cdots \\
    E_2 & = & x_{2}^{1} & x_{2}^{2} & x_{2}^{3}  & \cdots \\
    E_3 & = & x_{3}^{1} & x_{3}^{2} & x_{3}^{3}  & \cdots \\
    \cdots \\
}
;
\draw[->] (M-1-3.north east) -- (M-1-3.south west);
\draw[->] (M-1-4.north east) -- (M-2-3.south west);
\draw[->] (M-1-5.north east) -- (M-3-3.south west);
\draw[->] (M-1-3.north east) -- (M-1-3.south west);
\draw[->] (M-2-5.north east) -- (M-3-4.south west);
\draw[->] (M-3-5.north east) -- (M-3-5.south west);
\end{tikzpicture}

\end{document}

enter image description here

Related Question