Latex Beamer:在调整大小的 tikzpicture 上绘制箭头和文本,但文本应具有与演示文稿相同的字体

Latex Beamer:在调整大小的 tikzpicture 上绘制箭头和文本,但文本应具有与演示文稿相同的字体

我做了一个演示,并且有一个tikzpicture缩放比例resizebox

我现在想在 上绘制一个错误tikzmark,但箭头处的节点文本应与演示文稿的其余部分具有相同的字体大小,而不是与 tikzfigure 中的文本相同。

梅威瑟:

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{eucal}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{graphicx}
\usetheme{Madrid}

% tikz
\usepackage{tikz}
\usetikzlibrary{tikzmark,positioning}

% Mathematical stuff
\newcommand{\vect}[1]{\mathbf{\boldsymbol{#1}}} % bold vectors which also support greek letters
\newcommand{\mat}[1]{\mathbf{\boldsymbol{#1}}}  % bold matrices
\newcommand*{\tran}{^{\mkern-1.5mu\mathsf{T}}}

% for brackets: [[ ]]
\usepackage{stmaryrd}

\begin{document}
    \setbeamertemplate{navigation symbols}{}

    \tikzstyle{every picture}+=[remember picture]

    \begin{frame}{Matrix Decomposition}
    \begin{figure}
        \centering
        \resizebox{\textwidth}{!}{\begin{tikzpicture}
            \pgfmathsetmacro{\cubex}{1.5}
            \pgfmathsetmacro{\cubey}{1.5}

            % X
            \draw (0,0) node (start) {} --  ++(\cubex,0) -- ++(0,-\cubey) -- node[midway,above = 0.3*\cubey] {$\mat{X}$} node[midway,below] {data}++(-\cubex,0) -- cycle;

            \path (start) ++ (1.5*\cubex,-0.5*\cubey) node (approx) {$\approx$};

            % X_hat
            \draw (approx) ++ (0.5*\cubex,0.5*\cubey) node (lowrank) {} -- ++(\cubex,0) -- ++(0,-\cubey) -- node[midway,above = 0.3*\cubey] {$\mat{\hat{X}}$} node[midway,below] {low-rank model} ++(-\cubex,0) -- cycle;

            \path (lowrank) ++ (1.5*\cubex,-0.5*\cubey) node (equal) {=};

            % a_1, b_1
            \draw (equal) ++ (0.5*\cubex,0.5*\cubey-0.1*\cubey) node (1) {} -- ++(0.1*\cubex,0) -- ++(0,-\cubey)-- node[midway,below] {$\vect{a}_1$} ++(-0.1*\cubex,0) -- cycle;
            \draw (equal) ++ (0.5*\cubex+0.2*\cubex,0.5*\cubey) -- ++(\cubex,0) -- node[midway,right] {$\vect{b}_1$} ++(0,0.1*\cubey) -- ++(-\cubex,0) -- cycle;

            % red box
            \draw[rounded corners,red,thick] (1) ++ (-0.2*\cubex, 0.4*\cubey) -- ++(1.8*\cubex,0) -- ++(0,-1.8*\cubey) -- node (comp) {} ++(-1.8*\cubex,0) -- cycle;

            %% I could use these two lines, but then the font size is as the other letters in the tikzpicture, but different from the slides font size
            %\path (comp) ++ (2*\cubex,-\cubey) node[text=red] (comptext) {Component};
            %\path[->] (comptext.west) edge [ultra thick, red, bend left] (comp);

            \path (1) ++ (2*\cubex,-0.5*\cubey+0.1*\cubey) node (p2) {+};
            \path (p2) ++ (0.5*\cubex,0) node (dots) {\dots};
            \path (dots) ++ (0.5*\cubex,0) node (p3) {+};

            %a_R, b_R
            \draw (p3) ++ (0.5*\cubex,0.5*\cubey-0.1*\cubey) node (3) {} -- ++(0.1*\cubex,0) -- ++(0,-\cubey) -- node[midway,below] {$\vect{a}_R$} ++(-0.1*\cubex,0) -- cycle;
            \draw (p3) ++ (0.5*\cubex+0.2*\cubex,0.5*\cubey) -- ++(\cubex,0) -- node[midway,right] {$\vect{b}_R$} ++(0,0.1*\cubey) -- ++(-\cubex,0) -- cycle;

            \path (3) ++ (2*\cubex,-0.5*\cubey) node (equal2) {=};

            % A B.T
            \draw (equal2) ++ (0.5*\cubex,0.5*\cubey) node (A) {} --  ++(0.5*\cubex,0) -- ++(0,-\cubey) -- node[midway,above = 0.3*\cubey] {$\mat{A}$} ++(-0.5*\cubex,0) -- cycle;
            \path (A) ++ (0.5*\cubex,-0.5*\cubey) node (times) {};
            \draw (times) ++ (0.1*\cubex,0.5*\cubey) node (B) {} --  ++(\cubex,0) -- ++(0,-0.5*\cubey) -- node[midway,above = 0.05*\cubey] {$\mat{B}\tran$} ++(-\cubex,0) -- cycle;

            \end{tikzpicture}
        }
    \end{figure}

    %% when using these two lines, the label is wrong positioned
    %\tikz[overlay] {\path (comp) ++ (1,-1) node[text=red] (comptext) {Component};}
    %\tikz[overlay] {\path[->] (comptext.west) edge [ultra thick, red, bend left] (comp);}

    \begin{align*}
    \mat{X} \approx \mat{\hat{X}} = \sum_{r=1}^{R} \vect{a}_r \circ \vect{b}_r = \mat{A} \mat{B}\tran = \llbracket \mat{A}, \mat{B} \rrbracket
    \end{align*}
    \end{frame}

\end{document}

正如代码中的注释所写,我发现了两种可能性:

  1. 在 中绘制箭头和文本tikzpicture,但字体大小小于幻灯片上的其他文本( tikzpicture 中的两行注释)

在此处输入图片描述

  1. 在 外面绘制箭头和文本tikzpicture,字体大小现在没问题,但箭头指向错误的位置( 外面的两行注释\tikzpicture)。

在此处输入图片描述

我更喜欢解决第二个问题的解决方案,但我也对第一个问题的解决方案感到满意。

相关内容