如何在 TikZ 中发现矩阵的列?

如何在 TikZ 中发现矩阵的列?

我有以下投影仪框架,它有一个 4 列矩阵。关键是我想逐一揭开这些列,此外,我想在某个列结束和另一列开始的上方放置一个小文本,并在文本下方放置一个符号,例如“TEST \\ $\approx$”(红线显示在下面)。有什么想法如何在 TikZ 中实现这些?

在此处输入图片描述

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}
\usetheme{metropolis}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[beamer]{hf-tikz}
\usetikzlibrary{
    matrix,
    positioning,
    ext.node-families,
}
\DeclareMathOperator{\Enc}   {Enc} % instead of \mathsf{Enc}
\DeclareMathOperator{\PKey}  {PKey}
\DeclareMathOperator{\Sim}   {Sim}
\DeclareMathOperator{\Prover}{Prover}
\begin{document}

\begin{frame}{Intuition}
\begin{center}
\scriptsize
\begin{tikzpicture}
\matrix[
  nodes={draw=\bcol, fill=\fcol, rounded corners, node family/width=samewidth},
  matrix of math nodes,
  ampersand replacement = \&,
  row sep=.1cm,
  column sep=.2cm] {
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Prover(t^*, x, w) \end{aligned}
\& 
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Sim(t^*, x) \end{aligned}
\&
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Prover(t^*, x, w) \end{alignedat}
\& 
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Sim(t^*, x) \end{alignedat}
\\
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\&
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\& \text{too small} \& \text{to read}
\\};
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}

答案1

通过该overlay-beamer-styles库,您将可以访问visible on接受典型投影仪覆盖规范的密钥。

对于节点,我们仅使用计数\pgfmatrixcurrentcolumn,对于列上方的文本,我们仅使用东北角和西北角之间的未绘制路径。使用该calc库,您还可以指定

 at ($(m-1-1.north east)!.5!(m-1-2.north west)$)

对于节点。我会将其放入一个漂亮的循环中,这样您只需更改列表即可。

为此,我们需要给矩阵命名(此处(m)),然后每个单元格都可以作为使用(m-<row>-<column>)

作为替代方案,我添加了一个tikzcd解决方案,north connect使用 TikZ-CD 的选项来选择锚点。这path only确保实际上没有绘制任何线。TikZ-CD 有自己的phantom样式,但这确实会再次改变路径上节点的位置。

代码

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}
\usetheme{metropolis}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[beamer]{hf-tikz}
\usepackage{tikz-cd}
\usetikzlibrary{
    matrix,
    positioning,
    ext.node-families,
    overlay-beamer-styles
}
\DeclareMathOperator{\Enc}   {Enc} % instead of \mathsf{Enc}
\DeclareMathOperator{\PKey}  {PKey}
\DeclareMathOperator{\Sim}   {Sim}
\DeclareMathOperator{\Prover}{Prover}
\begin{document}

\begin{frame}{Intuition}
\begin{center}
\scriptsize
\begin{tikzpicture}
\matrix (m) [
  nodes={draw=\bcol, fill=\fcol, rounded corners,
    node family/width=samewidth,
    visible on=<\the\pgfmatrixcurrentcolumn->},
  matrix of math nodes,
  ampersand replacement = \&,
  row sep=.1cm,
  column sep=.2cm] {
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Prover(t^*, x, w) \end{aligned}
\& 
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Sim(t^*, x) \end{aligned}
\&
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Prover(t^*, x, w) \end{alignedat}
\& 
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Sim(t^*, x) \end{alignedat}
\\
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\&
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\& \text{too small} \& \text{to read}
\\};
\path[nodes={align=center, above}] 
  foreach \Text[count=\col from 2] in {
    Test\\$\approx$, Whee\\{$(2, 3)$}, Last\\One} {
    (m-1-\pgfinteval{\col-1}.north east)
     -- node[visible on=<\col->] {\Text} (m-1-\col.north west)
  };
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{Intuition}
\begin{center}
\scriptsize
\begin{tikzcd}[
  north connect/.style={path only, start anchor=north east, end anchor=north west, r},
  cells={nodes={draw=\bcol, fill=\fcol, rounded corners,
    node family/width=samewidth,
    visible on=<\the\pgfmatrixcurrentcolumn->
  }},
  ampersand replacement = \&,
  row sep=.1cm, column sep=.2cm, arrows=-, labels={font=},
  labels={math mode=false, align=center}]
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Prover(t^*, x, w) \end{aligned}
          \arrow[north connect, visible on=<2->, "Test\\$\approx$" visible on=<2->]
\& 
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Sim(t^*, x) \end{aligned}
          \arrow[north connect, visible on=<3->, "Whee\\{$(2, 3)$}" visible on=<3->]
\&
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Prover(t^*, x, w) \end{alignedat}
          \arrow[north connect, visible on=<4->, "Last\\One" visible on=<4->]
\& 
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Sim(t^*, x) \end{alignedat}
\\
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\&
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\& \text{too small} \& \text{to read}
\end{tikzcd}
\end{center}
\end{frame}
\end{document}

输出

在此处输入图片描述

答案2

您可以使用该overlay-beamer-styles库来按列揭示矩阵:

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}
\usetheme{moloch}% modern fork of the metropolis theme
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage[beamer]{hf-tikz}

\usetikzlibrary{overlay-beamer-styles}
\usetikzlibrary{
    matrix,
    positioning,
    ext.node-families,
}
\DeclareMathOperator{\Enc}   {Enc} % instead of \mathsf{Enc}
\DeclareMathOperator{\PKey}  {PKey}
\DeclareMathOperator{\Sim}   {Sim}
\DeclareMathOperator{\Prover}{Prover}
\begin{document}

\begin{frame}{Intuition}
\begin{center}
\scriptsize
\begin{tikzpicture}
\matrix[
  nodes={draw=\bcol, fill=\fcol, rounded corners, node family/width=samewidth, visible on=<\pgfmatrixcurrentcolumn->},
  matrix of math nodes,
  ampersand replacement = \&,
  row sep=.1cm,
  column sep=.2cm] {
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Prover(t^*, x, w) \end{aligned}
\& 
\begin{aligned} c_0 & \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                c_1 & \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
          \pi_{t^*} & \gets \Sim(t^*, x) \end{aligned}
\&
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Prover(t^*, x, w) \end{alignedat}
\& 
\begin{alignedat}{3} & c_0 && \gets \Enc(\PKey_0^{\mathsf{PKE}}, m_0) \\
                     & c_1 && \gets \Enc(\PKey_1^{\mathsf{PKE}}, m_0) \\
               & \pi_{t^*} && \gets \Sim(t^*, x) \end{alignedat}
\\
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\&
\mathsf{sk}_{f, t} = iO(\text{PKey}[\mathsf{sk}_0^{\mathsf{PKE}}, t])
\& \text{too small} \& \text{to read}
\\};
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}

在此处输入图片描述

相关内容