Math & ScienceDiagonal Arrows in a Matrix

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
elim
Posts: 10
Joined: Fri Jan 14, 2011 3:59 pm

Diagonal Arrows in a Matrix

Post by elim »

I don't know how to name it but wonder if the following can be specified by latex?
d_grph.jpg
d_grph.jpg (29.04 KiB) Viewed 7548 times
Thanks for your advise
Last edited by elim on Fri May 18, 2012 5:53 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Diagonal Arrows in a Matrix

Post by nlct »

You can use tikz (part of the pgf package) for that kind of thing.

Code: Select all

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\matrix (M)
{
  \node (x11) {$x_{11}$}; & \node (x12) {$x_{12}$}; 
   & \node (x13) {$x_{13}$}; & \node (x14) {$x_{14}$}; 
   & \node {\ldots};\\
  \node (x21) {$x_{21}$}; & \node {$x_{22}$}; & \node {$x_{23}$};
   & \node {$x_{24}$}; & \node {\ldots};\\
  \node (x31) {$x_{31}$}; & \node {$x_{32}$}; & \node {$x_{33}$};
   & \node {$x_{34}$}; & \node {\ldots};\\
  \node (x41) {$x_{41}$}; & \node {$x_{42}$}; & \node {$x_{43}$};
   & \node {$x_{44}$}; & \node {\ldots};\\
  \node {\ldots}; & \node {\ldots}; & \node {\ldots};
   & \node {\ldots}; & \node {\ldots};\\
};
\draw[->] (x11.south west) -- (x11.north east);
\draw[->] (x21.south west) -- (x12.north east);
\draw[->] (x31.south west) -- (x13.north east);
\draw[->] (x41.south west) -- (x14.north east);
\end{tikzpicture}

\end{document}
Regards
Nicola Talbot
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Diagonal Arrows in a Matrix

Post by Stefan Kottwitz »

Hi Elim!

Nicola already gave very good advice. Just a small addition, the code would be shorter and more readable if we would use the TikZ matrix library. Here's the code example of Nicola, using it:

Code: Select all

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

\begin{tikzpicture}
\matrix (m) [matrix of math nodes]
{
  x_{11} & x_{12} & x_{13} & x_{14} & \ldots \\
  x_{21} & x_{22} & x_{23} & x_{24} & \ldots \\
  x_{31} & x_{32} & x_{33} & x_{34} & \ldots \\
  x_{41} & x_{42} & x_{43} & x_{44} & \ldots \\
  \ldots & \ldots & \ldots & \ldots & \ldots \\
};
\draw[->] (m-1-1.south west) -- (m-1-1.north east);
\draw[->] (m-2-1.south west) -- (m-1-2.north east);
\draw[->] (m-3-1.south west) -- (m-1-3.north east);
\draw[->] (m-4-1.south west) -- (m-1-4.north east);
\end{tikzpicture}

\end{document}
And the output:
matrix.png
matrix.png (5.6 KiB) Viewed 7536 times
Stefan
LaTeX.org admin
elim
Posts: 10
Joined: Fri Jan 14, 2011 3:59 pm

Re: Diagonal Arrows in a Matrix

Post by elim »

Thanks a lot nlct and Stefan_K! Very nice solution!
Post Reply