这段代码有什么问题。
\begin{frame}
\frametitle{\textbf{\emph{m-way} Search Tree}}
\begin{figure}
\centering
\scalebox{0.4}{
\begin{tikzpicture}
\tikzset{every matrix/.style={inner sep=-\pgflinewidth,matrix of math nodes,column sep=-\pgflinewidth,nodes={draw=red,font=\color{blue},minimum size=.75cm,anchor=center}}}
\matrix[above] (t1) at (0,0) {18 & 44 & 76 & 198\\};
\matrix[below] (b1) at (0,0) {\bullet & \times & \times & \bullet & \bullet\\};
\matrix[above] (t21) at (-5,-4) {7 & 12\\};
\matrix[below] (b21) at (-5,-4) {\times & \bullet & \times\\};
\matrix[above] (t22) at (0,-4) {80 & 92 & 141\\};
\matrix[below] (b22) at (0,-4) {\bullet & \times & \times & \bullet\\};
\matrix[above] (t23) at (5,-4) {262\\};
\matrix[below] (b23) at (5,-4) {\times & \bullet\\};
\matrix[above] (t31) at (-7.5,-8) {8 & 10\\};
\matrix[below] (b31) at (-7.5,-8) {\times & \times & \times\\};
\matrix[above] (t32) at (-2.5,-8) {77\\};
\matrix[below] (b32) at (-2.5,-8) {\times & \times\\};
\matrix[above] (t33) at (2.5,-8) {148 & 151 & 172 & 186\\};
\matrix[below] (b33) at (2.5,-8) {\times & \times & \times & \times & \times\\};
\matrix[above] (t34) at (7.5,-8) {272 & 286 & 350\\};
\matrix[below] (b34) at (7.5,-8) {\times & \times & \times & \times\\};
\draw[blue] (b1-1-1.center) -- (t21-1-1.north east)
(b1-1-4.center) -- (t22-1-3.north)
(b1-1-5.center) -- (t23-1-1.north west)
(b21-1-2.center) -- (t31-1-1.north east)
(b22-1-1.center) -- (t32-1-1.north)
(b22-1-4.center) -- (t33-1-2.north east)
(b23-1-2.center) -- (t34-1-3.north);
\end{tikzpicture}
}
\vspace{-0.3cm} \caption{\emph{m-way} search tree}
\end{figure}
答案1
该beamer
课程与 Ti 配合不佳钾Z 的矩阵。要使其工作,您需要重置ampersand replacement
为\&
例如,并使用\&
列分隔:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{frame}
\frametitle{\textbf{\emph{m-way} Search Tree}}
\begin{figure}
\centering
\scalebox{0.4}{
\begin{tikzpicture}
\tikzset{every matrix/.style={inner sep=-\pgflinewidth,matrix of math nodes,column sep=-\pgflinewidth,nodes={draw=red,font=\color{blue},minimum size=.75cm,anchor=center},ampersand replacement=\&}}
\matrix[above] (t1) at (0,0) {18 \& 44 \& 76 \& 198\\};
\matrix[below] (b1) at (0,0) {\bullet \& \times \& \times \& \bullet \& \bullet\\};
\matrix[above] (t21) at (-5,-4) {7 \& 12\\};
\matrix[below] (b21) at (-5,-4) {\times \& \bullet \& \times\\};
\matrix[above] (t22) at (0,-4) {80 \& 92 \& 141\\};
\matrix[below] (b22) at (0,-4) {\bullet \& \times \& \times \& \bullet\\};
\matrix[above] (t23) at (5,-4) {262\\};
\matrix[below] (b23) at (5,-4) {\times \& \bullet\\};
\matrix[above] (t31) at (-7.5,-8) {8 \& 10\\};
\matrix[below] (b31) at (-7.5,-8) {\times \& \times \& \times\\};
\matrix[above] (t32) at (-2.5,-8) {77\\};
\matrix[below] (b32) at (-2.5,-8) {\times \& \times\\};
\matrix[above] (t33) at (2.5,-8) {148 \& 151 \& 172 \& 186\\};
\matrix[below] (b33) at (2.5,-8) {\times \& \times \& \times \& \times \& \times\\};
\matrix[above] (t34) at (7.5,-8) {272 \& 286 \& 350\\};
\matrix[below] (b34) at (7.5,-8) {\times \& \times \& \times \& \times\\};
\draw[blue] (b1-1-1.center) -- (t21-1-1.north east)
(b1-1-4.center) -- (t22-1-3.north)
(b1-1-5.center) -- (t23-1-1.north west)
(b21-1-2.center) -- (t31-1-1.north east)
(b22-1-1.center) -- (t32-1-1.north)
(b22-1-4.center) -- (t33-1-2.north east)
(b23-1-2.center) -- (t34-1-3.north);
\end{tikzpicture}
}
\vspace{-0.3cm} \caption{\emph{m-way} search tree}
\end{figure}
\end{frame}
\end{document}
输出
但是数字太小了。这是我推荐的版本
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{frame}
\frametitle{\textbf{\emph{m-way} Search Tree}}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.55]
\tikzset{every matrix/.style={inner sep=-\pgflinewidth,matrix of math nodes,column sep=-\pgflinewidth,nodes={draw=red,font=\color{blue}\footnotesize,minimum size=.55cm,anchor=center},ampersand replacement=\&}}
\matrix[above] (t1) at (0,0) {18 \& 44 \& 76 \& 198\\};
\matrix[below] (b1) at (0,0) {\bullet \& \times \& \times \& \bullet \& \bullet\\};
\matrix[above] (t21) at (-5,-4) {7 \& 12\\};
\matrix[below] (b21) at (-5,-4) {\times \& \bullet \& \times\\};
\matrix[above] (t22) at (0,-4) {80 \& 92 \& 141\\};
\matrix[below] (b22) at (0,-4) {\bullet \& \times \& \times \& \bullet\\};
\matrix[above] (t23) at (5,-4) {262\\};
\matrix[below] (b23) at (5,-4) {\times \& \bullet\\};
\matrix[above] (t31) at (-7.5,-8) {8 \& 10\\};
\matrix[below] (b31) at (-7.5,-8) {\times \& \times \& \times\\};
\matrix[above] (t32) at (-2.5,-8) {77\\};
\matrix[below] (b32) at (-2.5,-8) {\times \& \times\\};
\matrix[above] (t33) at (2.5,-8) {148 \& 151 \& 172 \& 186\\};
\matrix[below] (b33) at (2.5,-8) {\times \& \times \& \times \& \times \& \times\\};
\matrix[above] (t34) at (7.5,-8) {272 \& 286 \& 350\\};
\matrix[below] (b34) at (7.5,-8) {\times \& \times \& \times \& \times\\};
\draw[blue] (b1-1-1.center) -- (t21-1-1.north east)
(b1-1-4.center) -- (t22-1-3.north)
(b1-1-5.center) -- (t23-1-1.north west)
(b21-1-2.center) -- (t31-1-1.north east)
(b22-1-1.center) -- (t32-1-1.north)
(b22-1-4.center) -- (t33-1-2.north east)
(b23-1-2.center) -- (t34-1-3.north);
\end{tikzpicture}
\vspace{-0.3cm} \caption{\emph{m-way} search tree}
\end{figure}
\end{frame}
\end{document}