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 similar in looks to what you get here, though my tables don't contain numbers in their cells, and I'm looking for a solution that doesn't connect all and only pairwise adjacent cells. I'm not sure what the right way to modify this is.
I'm working with beamer
, and using tikz
(though I'm quite new to it) and tabularx
.
Is there a way to do this?
Edit: Here's a code like the one I'm messing with. I'm not sure how to fix.
\documentclass[pdf]{beamer}
\mode<presentation>{}
\usepackage[english]{babel}
\usepackage{natbib}
\usepackage{color, colortbl}
\renewcommand{\bibnumfmt}[1]{#1.}
\usepackage{ marvosym }
\usepackage{ tikzsymbols }
\usepackage{ wasysym }
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning, fit,shapes.misc}
\usetikzlibrary{decorations.pathreplacing, calc}
\newcommand{\tikzmark}[2][-3pt]{\tikz[remember picture, overlay, baseline=-0.5ex]\node[#1](#2){};}
\tikzset{brace/.style={decorate, decoration={brace}},
brace mirrored/.style={decorate, decoration={brace,mirror}},
}
\newcounter{brace}
\setcounter{brace}{0}
\newcommand{\drawbrace}[3][brace]{%
\refstepcounter{brace}
\tikz[remember picture, overlay]\draw[#1] (#2.center)--(#3.center)node[pos=0.5, name=brace-\thebrace]{};
}
\newcounter{arrow}
\setcounter{arrow}{0}
\newcommand{\drawcurvedarrow}[3][]{%
\refstepcounter{arrow}
\tikz[remember picture, overlay]\draw (#2.center)edge[#1]node[coordinate,pos=0.5, name=arrow-\thearrow]{}(#3.center);
}
\newcommand{\annote}[3][]{%
\tikz[remember picture, overlay]\node[#1] at (#2) {#3};
}
\newcommand\marktopleft[1]{
\tikz[overlay,remember picture]
\node (marker-#1-a) at (0,1.5ex) {};
}
\newcommand\markbottomright[1]{
\tikz[overlay,remember picture]
\node (marker-#1-b) at (0,0) {};
\tikz[overlay,remember picture,thick,dashed,inner sep=3pt]
\node[draw,rounded rectangle,fit=(marker-#1-a.center) (marker-#1-b.center)] {};
}
\usepackage{tabularx}
\usepackage{stmaryrd}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{xcolor}
\makeatletter
\newcommand{\redub}{}
\def\redub#1{%
\@ifnextchar_%
{\@redub{#1}}
{\@latex@warning{Missing argument for \string\redub}\@redub{#1}_{}}%
}
\def\@redub#1_#2{%
\colorlet{currentcolor}{.}%
\color{red}%
\underbrace{\color{currentcolor}#1}_{\color{red}#2}%
\color{currentcolor}%
}
\newcounter{savedenumi}
\newenvironment{moreenum}{%
\setcounter{savedenumi}{\value{enumi}}%
\begin{enumerate}\setcounter{enumi}{\value{savedenumi}}%
}{%
\end{enumerate}%
}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{}
\tableofcontents[currentsection]
\end{frame}
}
\newcolumntype{g}{>{\columncolor{red}}c}
\begin{document}
\begin{frame}
\begin{tabular}{ | l | l |}
\hline
letter & number \\ \hline
\tikzmark[xshift=-8pt,yshift=1ex]{x}A & 1\tikzmark[xshift=3.5em]{a} \\ \hline
A & 2 \\ \hline
\tikzmark[xshift=-8pt,yshift=-1ex]{y}A & 1\tikzmark[xshift=3.5em]{b} \\ \hline
\tikzmark[xshift=-8pt,yshift=1ex]{w}B & 1 \\ \hline
\tikzmark[xshift=-8pt,yshift=-1ex]{z}B & 2 \\ \hline
\end{tabular}
\drawcurvedarrow[bend left=60,-stealth]{a}{b}
\drawbrace[brace mirrored, thick]{x}{y}
\drawbrace[brace mirrored, thick]{w}{z}
\annote[right]{arrow-1}{Duplicate}
\annote[left]{brace-1}{A}
\annote[left]{brace-2}{B}
\tikzset{
every picture/.style={remember picture,baseline},
every node/.style={
inner sep=0pt,
anchor=base,
minimum width=1.8cm,
align=center,
text depth=.25ex,
outer sep=1.5pt},
every path/.style={
thick,
rounded corners
}
}
\begin{table}
\centering
\begin{tabular}{|c|c|c|g|c|}
\hline
bla & bla & bla & $b_1$\tikzmark{a} \\ \hline
bla & bla & bla & bla \\\hline
bla & bla & bla & bla \\\hline
bla & bla & bla & bla \\\hline
bla & bla & bla & bla \\\hline
\end{tabular}
\end{table}
\begin{tikzpicture}[remember picture,overlay]
\node [right=2cm,above=2cm,minimum width=0pt] at (pic cs:a) (A) {A};
\draw [<-,out=5,in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
Best Answer
For example, you could do the following if you rewrote your original code to use
tikzmark
. Note that I eliminated extraneous stuff from your MWE.This integrates the annotation commands with the drawing commands which saves having to define points for annotation later. It uses
calc
to adjust the positioning rather than altering the positioning of the original marks. This saves some counters. I found putting everything in a single overlay picture worked better than worrying about making a bunch of commands work together but your kilometres may obviously vary.