我希望能夠在頂部繪製一個帶有一些文字的箭頭,連接帶有左向箭頭的表格的兩個任意(即可能非最右/最左,可能不相鄰)單元格。特別是,我試圖在表格頂部獲得一個與您所得到的類似的箭頭這裡,儘管我的表格的單元格中不包含數字,並且我正在尋找一種不連接所有且僅連接成對相鄰單元格的解決方案。我不確定修改這個的正確方法是什麼。
我正在使用beamer
, 並使用tikz
(儘管我對它很陌生)和tabularx
.
有沒有辦法做到這一點?
編輯:這是一段類似我正在搞亂的程式碼。我不知道如何修復。
\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}
答案1
例如,如果您重寫原始程式碼以使用tikzmark
.請注意,我從您的 MWE 中刪除了無關的內容。
\documentclass[pdf]{beamer}
\mode<presentation>{}
\usepackage[english]{babel}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning, fit, shapes.misc}
\usetikzlibrary{decorations.pathreplacing, calc}
\tikzset{brace/.style={decorate, decoration={brace}},
brace mirrored/.style={decorate, decoration={brace,mirror}},
}
\newcolumntype{g}{>{\columncolor{red}}c}
\begin{document}
\begin{frame}
\begin{tabular}{ | l | l |}
\hline
letter & number \\ \hline
\tikzmark{x}A & 1\tikzmark{a} \\ \hline
A & 2 \\ \hline
\tikzmark{y}A & 1\tikzmark{b} \\ \hline
\tikzmark{w}B & 1 \\ \hline
\tikzmark{z}B & 2 \\ \hline
\end{tabular}
\begin{tikzpicture}[remember picture, overlay]
\draw ($(pic cs:a) + (3.5em,0)$) edge[bend left=60,-stealth] ($(pic cs:b) + (3.5em,0)$) node [midway, right, xshift=5pt, yshift=5pt] {Duplicate};
\draw[brace mirrored, thick] ($(pic cs:x) + (-8pt,1ex)$)--($(pic cs:y) + (-8pt,-1ex)$) node [midway, left] {A};
\draw[brace mirrored, thick] ($(pic cs:w) + (-8pt,1ex)$)--($(pic cs:z) + (-8pt,-1ex)$) node [midway, left] {B};
\end{tikzpicture}
\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{c} \\ \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:c}) (A) {A};
\draw [<-,out=5,in=180] ([xshift=15pt]{pic cs:c}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
這將註釋命令與繪圖命令整合在一起,從而無需稍後定義註釋點。它用於calc
調整位置而不是改變原始標記的位置。這可以節省一些計數器。我發現將所有內容放在一張疊加圖片中比擔心一堆命令一起工作要好,但您的公里數可能明顯不同。