3

Here's a MWE

\documentclass{article} \usepackage{float} \usepackage{amsmath} \usepackage{array} \begin{document} \begin{table}[H] \def\arraystretch{1.5} \begin{tabular}{|c | c | c l} \cline{1-2} $A$ & $B$ & $\Longleftarrow$ & {\setlength\extrarowheight{-30pt} \begin{tabular}{@{}l@{}} Some \\ text \end{tabular}} \\ \cline{1-2} $C$ & $D$ & $\Longleftarrow$ & {\setlength\extrarowheight{-30pt}\begin{tabular}{@{}l@{}} Some other \\ text \end{tabular}} \\ \cline{1-2} \end{tabular} \end{table} \end{document} 

which produces

enter image description here

I would like to add arrows of this sort (proportionately sized, pardon my artistic inabilities)

enter image description here

What is the most efficient way of doing so without modifying the table code? Note that the table has to go into a beamer slide.

3 Answers 3

5

With tikz and the matrix library. To make the cells the same size, I set minimum width=2em and minimum height=2em to modify, if we change to 2x+1 for example.

you need more than 1.6em, otherwise...

To avoid double rows in the table, I use [-\pgflinewidth] to separate the columns (at the first row) and at each line break.

Don't forget execute at begin cell=\mathstrut

Code

 \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,arrows.meta} \begin{document} \begin{tikzpicture} [ mytips/.tip = {Straight Barb[width=2pt]}, mytipsii/.tip = {Implies[]}, Ar/.style={ mytips-mytips, blue, shorten >=5pt, shorten <=5pt, }, Arii/.style={ double, mytipsii-, }, ] \matrix (magic) [ matrix of math nodes, nodes={ draw, minimum width=2em, minimum height=2em, }, execute at begin cell=\mathstrut ] { A&[-\pgflinewidth] B\\[-\pgflinewidth] x&D\\ }; \draw[Ar] (magic-2-1.center) -- (magic-1-2.center); \draw[Ar] (magic-1-1.center) -- (magic-2-2.center); \draw [Arii] (magic-1-2.east)++(1em,0) --++(2em,0)node[right] {Some text}; \draw [Arii] (magic-2-2.east)++(1em,0) --++(2em,0)node[right] {\parbox{2cm}{Some other\\text}}; \end{tikzpicture} \end{document} 

enter image description here

4

Here is a solution with {NiceTabular} of nicematrix and TikZ to draw the arrows by using the PGF/TikZ nodes added by nicematrix under the cells of the array.

\documentclass{article} \usepackage{nicematrix,tikz} \begin{document} \renewcommand{\arraystretch}{1.5} \begin{NiceTabular}{cccl} \Block[hvlines]{2-2}{} $A$ & $B$ & $\Longleftarrow$ & \Block{}{Some\\ text} \\ $C$ & $D$ & $\Longleftarrow$ & \Block{}{Some other\\ text} \CodeAfter \begin{tikzpicture} [blue, <->, shorten > = 3pt, shorten < = 3pt] \draw (1-1) -- (2-2) ; \draw (2-1) -- (1-2) ; \end{tikzpicture} \end{NiceTabular} \end{document} 

You need several compilations.

Output of the above code

The blue arrows don't across exactly at the intersection of the vertical rule and the horizontal rule (because the labels A, B, C and D don't have exactly the same size).

It's possible to draw arrows with exactly the same size which cross at the intersection of the rules with the following code:

\documentclass{article} \usepackage{nicematrix,tikz} \begin{document} \renewcommand{\arraystretch}{1.5} \begin{NiceTabular}{cccl} \Block[hvlines]{2-2}{} $A$ & $B$ & $\Longleftarrow$ & \Block{}{Some\\ text} \\ $C$ & $D$ & $\Longleftarrow$ & \Block{}{Some other\\ text} \CodeAfter \begin{tikzpicture} [blue, ->] \draw (2-|2) -- ++ (2mm,2mm) ; \draw (2-|2) -- ++ (-2mm,2mm) ; \draw (2-|2) -- ++ (2mm,-2mm) ; \draw (2-|2) -- ++ (-2mm,-2mm) ; \end{tikzpicture} \end{NiceTabular} \end{document} 

Output of the second code

2

Here is a (almost) pure LaTeX solution: It draws the arrows on top of the table by putting everything inside a standard picture environment:

\documentclass{article} \usepackage{float} \usepackage{amsmath} \usepackage{array} \usepackage{color} \usepackage{pict2e} \begin{document} \begin{table}[H] \setlength{\unitlength}{1mm} \begin{picture}(50,25)(-10,-10) % The original tabular is placed here: \put(0,0) { \def\arraystretch{1.5} \begin{tabular}{|c | c | c l} \cline{1-2} $A$ & $B$ & $\Longleftarrow$ & {\setlength\extrarowheight{-30pt} \begin{tabular}{@{}l@{}} Some \\ text \end{tabular}} \\ \cline{1-2} $C$ & $D$ & $\Longleftarrow$ & {\setlength\extrarowheight{-30pt}\begin{tabular}{@{}l@{}} Some other \\ text \end{tabular}} \\ \cline{1-2} \end{tabular} } % Here is the arrow part \color{blue} \put(9.5,0.75){\vector(1,1){2}} \put(9.5,0.75){\vector(1,-1){2}} \put(9.5,0.75){\vector(-1,1){2}} \put(9.5,0.75){\vector(-1,-1){2}} \end{picture} \end{table} \end{document} 

The placement of the arrow origin took a few trials. I'm sure there is a more intelligent way of calculating that from table parameters but I didn't do it.

The package pict2e is necessary to overcome some (rather strict) shortcomings of the picture environment, such as not allowing lines and arrows shorter than 10 pt. (Also many angles are forbidden. I often feel that pict2e should have be incorporated into the latex kernel, but anyway.)

The output

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.