Home > tikz pgf > How to Create a Table in Tikz with Arrows from One Cell to Another?

How to Create a Table in Tikz with Arrows from One Cell to Another?

April 15Hits:1
Advertisement

I would like to reproduce a table in tikz with arrows from predefined cell to another predefined cell.

Something looks like this.

How to Create a Table in Tikz with Arrows from One Cell to Another?

What I did was the following:

\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc,matrix,positioning}  \tikzset{      table/.style={         matrix of nodes,         row sep=-\pgflinewidth,         column sep=-\pgflinewidth,         nodes={rectangle,text width=3em,align=center},         text depth=1.25ex,         text height=2.5ex,         nodes in empty cells     }, } \begin{document}   \begin{tikzpicture}     % the matrix entries     \matrix (mat) [table]     {     & $x$ & $y$ & $z$ \\     $x$ & a  & a & b \\     $y$ & b & a & c \\     $z$ & c & d & e \\     };     % the matrix rules     \foreach \x in {1,...,3}     {       \draw          ([xshift=-.5\pgflinewidth]mat-\x-1.south west) --            ([xshift=-.5\pgflinewidth]mat-\x-4.south east);       }     \foreach \x in {1,...,3}     {       \draw          ([yshift=.5\pgflinewidth]mat-1-\x.north east) --          ([yshift=.5\pgflinewidth]mat-4-\x.south east);     }         % the arrows     \begin{scope}[shorten >=7pt,shorten <= 7pt]     \draw[->]  (mat-4-4.center) -- (mat-3-4.center);     \draw[->]  ([shift={(2.5pt,3pt)}]mat-4-4.center) -- ([shift={(2.5pt,2.5pt)}]mat-2-4.center);     \draw[->]  ([shift={(8pt,8pt)}]mat-2-4.center) -- ([shift={(8pt,8pt)}]mat-2-3.center);     \end{scope}     \end{tikzpicture} \end{document} 

But as you can see by reproducing the output of the above code, the arrows are note good in the sense that are not aligned.

Note: Some of the above code was found in this site but I can't remember exactly the link.

EDIT: Here is the output of my code:

How to Create a Table in Tikz with Arrows from One Cell to Another?

Answers

Using a normal tabular along with the tikzmark library would be much easier. After marking the required positions and giving names for them, using \tikzmark{<a name>}, then comes a tikzpicture to draw the actual arrows as given below. Fine tuning may be required to get the best result.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\renewcommand{\arraystretch}{1.5}
\begin{tabular}{c|c|c|c}
        & $x$ & $y$ & $z$ \\ \hline
    $x$ & a   & a\tikzmark{a}   & b\tikzmark{b}   \\ \hline
    $y$ & b   & a   & \tikzmark{c}c  \\ \hline
    $z$ & c   & d   & \tikzmark{e}e\tikzmark{ee}   \\
\end{tabular}

\begin{tikzpicture}[overlay,remember picture, shorten >=-3pt]
\draw[->,yshift=2ex] (pic cs:b) -- (pic cs:a) ;
\draw[->,xshift=-.7ex] (pic cs:e) -- (pic cs:c);
\draw[->,xshift=0.7ex] (pic cs:ee) -- (pic cs:b);
\end{tikzpicture}

\end{document}

How to Create a Table in Tikz with Arrows from One Cell to Another?

Tags:tikz pgf

Related Articles

  • How to Create a Table in Tikz with Arrows from One Cell to Another?

    How to Create a Table in Tikz with Arrows from One Cell to Another?April 15

    I would like to reproduce a table in tikz with arrows from predefined cell to another predefined cell. Something looks like this. What I did was the following: \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc,matrix,positioning} \tik

  • Annotating Tables With Tikz; Adding Arrows

    Annotating Tables With Tikz; Adding ArrowsMarch 22

    I'd like to be able to draw an arrow with some text on top connecting two arbitrary (i.e. possibly non-right-/left-most, possibly nonadjacent) cells of a table with a left-looking arrow. In particular, I'm trying to get an arrow on the top of a table

  • Creating table using TikZ matrix

    Creating table using TikZ matrixJuly 31

    I'm trying to create a table in TikZ with the first column right-aligned, and the texts in each cell on the same line the rest of the columns center-aligned, and each has width of 1cm My attempt is as follows: \documentclass{article} \usepackage{tikz

  • Is there a standard package to create a table like this?

    Is there a standard package to create a table like this?June 7

    Is there a fast and efficient way to create a table with a vertical arrow like this? A suitable reference or a snippet of LaTeX code would be much appreciated. --------------Solutions------------- Here's an outline answer using tabularx and tikz. I a

  • Table with tikz image: vertical alignment

    Table with tikz image: vertical alignmentMay 24

    I'm trying to create simple table with tikz pictures and its descriptions on the left side. Unfortunately I cannot vertically center those descriptions in their cells: \documentclass[a4paper,fleqn,leqno]{article} \usepackage{polyglossia} \usepackage{

  • Create a table for an athletic knockout event

    Create a table for an athletic knockout eventNovember 22

    I have used LaTeX for fairly large documents in the past but not for diagrams. I would like to create a table describing a knockout athletic event, for instance like the one found here in HTML. How would I go about creating such a thing in LaTeX? Per

  • Create a table with calculations of binomial and poisson distribution

    Create a table with calculations of binomial and poisson distributionNovember 25

    Well, I was looking for some tables on the internet about the binomial and poisson distribution (not the cumulative ones) in LaTeX format. But I've only found the code of the cumulative distributions, which I don't want. Then I looked around for othe

  • How to create a table with some rows merged on the right column

    How to create a table with some rows merged on the right columnSeptember 11

    I want to create a table like There are 2 cells in the 4th column which are merged vertically on the right side. While it is easy to merge them on the left side using multirow, I'm at a loss on how to merge on the right side Here is my source code (u

  • Trouble creating basic table

    Trouble creating basic table April 21

    This question already has an answer here: How to create fixed width table columns with text raggedright/centered/raggedleft? 2 answers I would like to create a table, which look like this: \documentclass[a4paper,12pt,oneside]{article} \usepackage[eng

  • Is it possible to create a table with two entries in one cell separated by 45 degree line?

    Is it possible to create a table with two entries in one cell separated by 45 degree line? August 3

    This question already has an answer here: Diagonal lines in table cell 4 answers I want to create a table like the below picture in LaTeX. Does anyone tried this before? Can you introduce how to create such a table? The problem is that I don't know t

  • Creating temp tables in SQL SERVER? February 8

    In SQL Server, what is the difference between a @ table, a # table and a ## table? --------------Solutions------------- #table refers to a local (visible to only the user who created it) temporary table. ##table refers to a global (visible to all use

  • Creating sphinx table in mysql crashes mysql - why?April 22

    I've got the latest version of sphinx installed. I have created the index with no problems and searchd starts up with no problems. However, whenever I try to create a test table (straight from the docs I might add) mysql crashes. I'm at wits end here

  • Automatically drop FK's to re-create a table and then automatically put the FK's backSeptember 22

    I have a number of incidents where SSMS tells me table recreation is required, even for something simple like making a column nullable. If this table is referenced by FK's, I would ideally like to find a way of temporarily removing those FK's from th

  • MS Word - create a table with 2 rows, where each row is 50% of the document's heightOctober 5

    I need to create a table with 2 rows, where each row is 50% of the document's height (assume portrait orientation). Is there an easy way to do this? --------------Solutions------------- I decided the easiest way to do this was simply to set the row h

  • Create data table in geodatabaseJanuary 5

    Using vb.net, my custom tool needs to create a data table in my geodatabase to store some information for later use. The user will be in ArcMap 9.3.1 with the geodatabase up and layers displayed. I want to create the table at the same level as the da

  • Saving a Word document to PDF, how to create a table of contents?March 11

    How do I create a table of contents when saving a Word document and saving as a PDF file? That is, when you buy an e-book, it has a nice table of contents in the left pane that remains there while you read, and you can jump around the PDF file. -----

  • Force ArcCatalog to refresh TreeView and View after programmatically creating a tableMarch 31

    I'm programmatically creating a table in a geodatabase and am trying to force ArcCatalog to refresh the display to show the new table. I've tried the following which does not work: Dim gxApp As IGxApplication = TryCast(m_application, IGxApplication)

  • Creating a table that uses all available space

    Creating a table that uses all available spaceApril 9

    Is there a way to use tabular or some other method to create a table that expands to use the entire available space? So if I created a table with 4 rows, each row would use 25% of the space. Thanks! --------------Solutions------------- Possible with

  • Creating spatial tables with PostGISApril 18

    In the PostGIS documentation it says that there are two steps to creating a spatial table with SQL: Create a normal non-spatial table. Add a spatial column to the table using the OpenGIS "AddGeometryColumn" function. If I followed the examples,

  • How to create a table of random characters in XeTeX

    How to create a table of random characters in XeTeXJune 10

    I want to create a table of 1000 characters picked randomly from the unicode block "unified CJK ideograms" (4E00-9FFF). Each cell should contain exactly one huge character, no character should appear twice. It would be great too if one could spe

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.756 s.