Draw an arrow that connect each column by the corresponding entry in LaTeX

In summary: For example, if I want to remove the last row with the arrow, I can simply remove the code for that row, and the arrow will be removed as well. You can also add the option "nodes in empty cells" to your table style, and any empty cells will not be shown.
  • #1
EngWiPy
1,368
61
Hello,

I have the following Latex code, and I need to draw an arrow that connect each column by the corresponding entry in the last (separated) row, e.g.: the column [x_0^{(1)} x_0^{(2)} ... x_0^{(M)}]^T with the entry x_0^{(R)} and so on. How can I do that?

Code:
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\begin{document}

\tikzset{ 
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center
        },
        minimum height=1.5em,
        text depth=0.5ex,
        text height=2ex,
        nodes in empty cells,
%%
        %every even row/.style={
            %nodes={fill=gray!20}
        %},
        column 1/.style={
            nodes={text width=2em,font=\bfseries}
        },
				column 2/.style={
            nodes={text=red}
        },
				column 3/.style={
            nodes={text=blue}
        },
				column 5/.style={
            nodes={text=violet}
        },
        row 5/.style={
            nodes={
                fill=gray!20,
                %text=black,
                font=\bfseries
            }
        }
    }
}

\begin{tikzpicture}

\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
$\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$ \\[10mm]
$\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};


\end{tikzpicture}
\end{document}

Thanks in advance
 
Physics news on Phys.org
  • #2
I did one for you. I checked out this site for examples, always love learning new latex packages.

www.texample.net/tikz/examples/feature/arrows/

Basically I labelled to areas using the label maker for nodes : |[name=a]|

Then after the matrix I drew an arrow from a to b. So repeat wherever you need it.

Code:
\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
|[name=a]| $\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$\\[10mm]
|[name=b]| $\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};
 \draw[->,thick] (a) edge (b);
 
  • #3
Hepth said:
I did one for you. I checked out this site for examples, always love learning new latex packages.

www.texample.net/tikz/examples/feature/arrows/

Basically I labelled to areas using the label maker for nodes : |[name=a]|

Then after the matrix I drew an arrow from a to b. So repeat wherever you need it.

Code:
\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
|[name=a]| $\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$\\[10mm]
|[name=b]| $\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};
 \draw[->,thick] (a) edge (b);

Perfect. Look very nice. Thanks
 
  • #4
Another question: How can I remove a cell completely?
 
  • #5
for your help!

I would recommend using the TikZ library "arrows.meta" to draw arrows connecting the columns to the corresponding entry in the last row. You can add the following code after the matrix declaration in your existing code:

\begin{tikzpicture}
\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$ & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$ & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ \\
$\mathbf{x}^{(M)}$ & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$ \\[10mm]
$\mathbf{x}^{(R)}$ & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};

% Add arrows
\draw[->] (first-1-2) to (first-6-2);
\draw[->] (first-1-3) to (first-6-3);
\draw[->] (first-1-4) to (first-6-4);
\draw[->] (first-1-5) to (first-6-5);

\end{tikzpicture}

This will draw arrows connecting each column in the first row to the corresponding entry in the last row. You can adjust the positioning and styling of the arrows as needed. Hope this helps!
 

Related to Draw an arrow that connect each column by the corresponding entry in LaTeX

1. How do I draw an arrow in LaTeX?

In order to draw an arrow in LaTeX, you can use the \rightarrow command for a right-pointing arrow or the \leftarrow command for a left-pointing arrow.

2. How do I connect columns with arrows in LaTeX?

To connect columns with arrows in LaTeX, you can use the \xrightarrow{entry} command to create a right-pointing arrow with the specified entry above it. Similarly, you can use the \xleftarrow{entry} command for a left-pointing arrow.

3. How can I create a double-headed arrow in LaTeX?

To create a double-headed arrow in LaTeX, you can use the \leftrightarrow command. You can also use the \xleftrightarrow{entry} command to add a specific entry above the arrow.

4. Can I customize the appearance of arrows in LaTeX?

Yes, you can customize the appearance of arrows in LaTeX by using the \xrightarrow[above]{below} and \xleftarrow[above]{below} commands. Here, you can specify the text to be displayed above and below the arrow.

5. Is there a way to create curved arrows in LaTeX?

Yes, you can create curved arrows in LaTeX by using the \xrightarrow{entry}_{curve} and \xleftarrow{entry}_{curve} commands. Here, you can specify the entry and the degree of curvature for the arrow.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
304
  • Linear and Abstract Algebra
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Topology and Analysis
Replies
12
Views
3K
Back
Top