围绕 tikz-cd 的框

围绕 tikz-cd 的框

关于这段代码,我想在这些tikz-cds 周围创建两个框。可以吗?非常感谢。代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage{tikz}
\usepackage{tikz-cd}
\usepackage{stix}
\usepackage[bb=ams]{mathalpha}
\usepackage{mathtools}

\newcommand{\tonde}[1]{\bigl(#1\bigr)}

\newcommand{\R}{\mathbb R}
\newcommand{\A}{\mathbb A}

\title{TikZ - tikzsets}
\author{PUCK}
\date{November 2022}

\begin{document}

\maketitle

\Large

\section{Introduction}

\begin{equation}
\begin{tikzcd}[arrow style=tikz, >={Triangle[length=2mm]}, cells={nodes={inner sep=2mm}}, row sep=1.25cm,column sep=2cm]
M\arrow[r, "f\in C^\infty"] & N \\ g\tonde{U} \arrow[u, hook, "i_M"] \arrow[r, "\bar{f}\in C^\infty"] & h\tonde{V}\arrow[u, hook, "i_N"']\\U\arrow[u, hook, two heads, "g", "\eqqsim"'] \arrow[r, hook, two heads, "\phi\coloneqq h^{-1}\circ f\circ g","\eqqsim"'] &V\arrow[u, hook, "h"', "\eqqsim"]
\end{tikzcd}\implies
\begin{tikzcd}[arrow style=tikz, >={Triangle[length=2mm]}, cells={nodes={inner sep=2mm}}, row sep=1.5cm, column sep=2cm]
\textbf{T}_xM\subset\R^k\arrow[r, "df_x"] & \textbf{T}_yN \subset\R^l\\\textbf{T}_uU=\R\A^m\arrow[r, "d\phi_u"'] \arrow[u, "dg_u"] & \textbf{T}_vV=\R\A^n \arrow[u, "dh_v"']
\end{tikzcd}
\end{equation}

\end{document}

Box Tikz-cd

答案1

您可以使用backgrounds图书馆库绘制一个围绕整个图表的矩形框。有关如何更改该矩形结果的更多选项,请参阅手册,主要是内框分隔符的设置。

我也

  • 用于定义。\DeclarePairedDelimitermathtools\tonde

    现在您可以使用\tonde*{<stuff>},并且括号会自动缩放,但您也可以使用\tonde[\big]{<stuff>},并且\bigl(<stuff>\bigr)将被排版。(对于单个,V无需使用\big?。)

  • 为图表定义了my CD重复设置的样式。如果您希望所有图表都具有这些选项,您只需将这些选项附加到every diagram

    \tikzcdset{every diagram/.append style={…}}
    
  • 用来\mathbf代替\textbf

  • \diff并为差速器定义了一个d(并注释掉了直立式的版本d)。

amsmath包还提供了\boxed可以在此处使用的宏,但没有 TikZ 带来的全部功能。

代码

\documentclass{article}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage{tikz-cd}
\usepackage{stix}
\usepackage[bb=ams]{mathalpha}
\usepackage{mathtools}
\newcommand{\R}{\mathbb R}
\newcommand{\A}{\mathbb A}

\DeclarePairedDelimiter{\tonde}() % better then your own \tonde
\newcommand*{\diff}{d}            % diff d italic
%\newcommand*{\diff}{\mathup{d}}   % diff d upright
\usetikzlibrary{backgrounds}      % for background rectangle
\tikzcdset{
  my CD/.style={                  % shortcut for repeated style
    arrow style=tikz,
    >={Triangle[length=2mm]},
    cells={nodes={inner sep=2mm}},
    row sep=1.25cm,  column sep=2cm}}
\tikzset{
  boxed/.style={                  
    show background rectangle,    % adds a box around the whole picture
    background rectangle/.append style={ % that is red, thick and rounded
      draw=red, thick, rounded corners}}}
\begin{document}
\Large
\section{Introduction}

\begin{equation}
\begin{tikzcd}[my CD, boxed]
 M              \arrow[r, "f\in C^\infty"] & N \\
 g\tonde{U}     \arrow[u, hook, "i_M"]
                \arrow[r, "\bar{f}\in C^\infty"]
   & h\tonde{V} \arrow[u, hook, "i_N"'] \\
 U              \arrow[u, hook, two heads, "g", "\eqqsim"']
                \arrow[r, hook, two heads,
                       "\phi\coloneqq h^{-1}\circ f\circ g", "\eqqsim"']
   & V          \arrow[u, hook, "h"', "\eqqsim"]
\end{tikzcd}
\implies
\begin{tikzcd}[my CD, boxed]
 \mathbf{T}_xM \subset\R^k    \arrow[r, "\diff f_x"    ]
   & \mathbf{T}_yN \subset\R^l \\
 \mathbf{T}_uU=\R\A^m         \arrow[r, "\diff \phi_u"']
                              \arrow[u, "\diff g_u"    ]
   & \mathbf{T}_vV=\R\A^n     \arrow[u, "\diff h_v"'   ]
\end{tikzcd}
\end{equation}
\end{document}

输出

在此处输入图片描述

答案2

我建议在矩阵中附加一种样式(CD 是 TikZ 矩阵),为了方便起见,我创建了mymatr样式(根据 Qrrbrbirlbel 的建议进行更新):

\documentclass{article}
%\usepackage[utf8]{inputenc} no more needed in up-to-date distributions: https://tex.stackexchange.com/a/370279/101651
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
%\usepackage{tikz} not needed, tikz-cd already load it
\usepackage{tikz-cd}
\tikzset{mymatr/.style={every outer matrix/.append style={draw=red, inner xsep=4pt , inner ysep=6pt, rounded corners, very thick}}}

\usepackage{stix}
\usepackage[bb=ams]{mathalpha}
\usepackage{mathtools}

\newcommand{\tonde}[1]{\bigl(#1\bigr)}

\newcommand{\R}{\mathbb R}
\newcommand{\A}{\mathbb A}

\title{TikZ - tikzsets}
\author{PUCK}
\date{November 2022}

\begin{document}

\maketitle

\Large

\section{Introduction}

\begin{equation}
\begin{tikzcd}[mymatr, 
arrow style=tikz, >={Triangle[length=2mm]}, cells={nodes={inner sep=2mm}}, row sep=1.25cm,column sep=2cm]
M\arrow[r, "f\in C^\infty"] & N \\ g\tonde{U} \arrow[u, hook, "i_M"] \arrow[r, "\bar{f}\in C^\infty"] & h\tonde{V}\arrow[u, hook, "i_N"']\\U\arrow[u, hook, two heads, "g", "\eqqsim"'] \arrow[r, hook, two heads, "\phi\coloneqq h^{-1}\circ f\circ g","\eqqsim"'] &V\arrow[u, hook, "h"', "\eqqsim"]
\end{tikzcd}\implies
\begin{tikzcd}[mymatr,  
arrow style=tikz, >={Triangle[length=2mm]}, cells={nodes={inner sep=2mm}}, row sep=1.5cm, column sep=2cm]
\textbf{T}_xM\subset\R^k\arrow[r, "df_x"] & \textbf{T}_yN \subset\R^l\\\textbf{T}_uU=\R\A^m\arrow[r, "d\phi_u"'] \arrow[u, "dg_u"] & \textbf{T}_vV=\R\A^n \arrow[u, "dh_v"']
\end{tikzcd}
\end{equation}

\end{document}

在此处输入图片描述

答案3

像这样?

在此处输入图片描述

编辑:
删除了preview用于仅查看带tikzcd图表的方程式的包的使用。看来 OP 不知道这个技巧,所以最好删除它。现在编译结果显示在整页顶部。希望现在提出的解决方案更加清晰。

矩形被绘制为fit节点execute at end picture

\documentclass{article}
\usepackage{stix}
\usepackage[bb=ams]{mathalpha}
\usepackage{mathtools}
\newcommand{\R}{\mathbb R}
\newcommand{\A}{\mathbb A}

\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,
                fit,
                patterns.meta}
\tikzcdset{
arrow style=tikz, 
>={Triangle[length=2mm]}, 
cells={nodes={inner sep=2mm}},
        }
\tikzset{
every matrix/.append style = {name=m},
F/.style = {draw=red, very thick, rounded corners, inner sep=5pt, fit=#1}
        }

\begin{document}
\begin{equation}
    \begin{tikzcd}[column sep=24mm, row sep=12mm,
execute at end picture = { % <----
    \node[F = (m-1-1) (m-3-2) ] {};
                        }% end of execute at end picture
                    ]
M \rar["f\in C^\infty"] & N     \\ 
g(U) \uar[hook, "i_M"] \rar["\bar{f}\in C^\infty"] 
                        & h(V)\uar[hook, "i_N"']   \\
U \uar[hook, two heads, "g", "\eqqsim"'] 
  \rar[hook, two heads, "\phi\coloneqq h^{-1}\circ f\circ g","\eqqsim"'] 
                        & V \uar[hook, "h"', "\eqqsim"]
    \end{tikzcd}
  \implies
    \begin{tikzcd}[sep=12mm,
execute at end picture = {% <----
    \node[F = (m-1-1) (m-2-2) ] {};
                        }% end of execute at end picture
                    ]
\textbf{T}_xM\subset\R^k \rar["df_x"] 
                        & \textbf{T}_yN \subset\R^l \\
\textbf{T}_uU=\R\A^m \rar["d\phi_u"'] 
                     \uar["dg_u"] 
                        & \textbf{T}_vV=\R\A^n \uar["dh_v"']
    \end{tikzcd}
\end{equation}
\end{document}

附录:

  • 未定义\tikzset节点样式的通用名称。样式现已在节点中定义。
  • 矩阵的命名被图表名称every matrix/.append style = {name=m}的替代:tikz@f@...
\documentclass{article}
\usepackage{stix}
\usepackage[bb=ams]{mathalpha}
\usepackage{mathtools}
\newcommand{\R}{\mathbb R}
\newcommand{\A}{\mathbb A}

\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,
                fit,
                patterns.meta}
\tikzcdset{
arrow style=tikz,
>={Triangle[length=2mm]},
          }

\begin{document}
\begin{preview}
\begin{equation}
    \begin{tikzcd}[column sep=24mm, row sep=12mm,
execute at end picture = { % <----
    \node[draw=red, very thick, rounded corners, fit=(tikz@f@1)] {}; % first diagram
                        }% end of execute at end picture
                    ]
M \rar["f\in C^\infty"] & N     \\
g(U) \uar[hook, "i_M"] \rar["\bar{f}\in C^\infty"]
                        & h(V)\uar[hook, "i_N"']   \\
U \uar[hook, two heads, "g", "\eqqsim"']
  \rar[hook, two heads, "\phi\coloneqq h^{-1}\circ f\circ g","\eqqsim"']
                        & V \uar[hook, "h"', "\eqqsim"]
    \end{tikzcd}
  \implies
    \begin{tikzcd}[sep=12mm,
execute at end picture = {% <----
    \node[draw=red, very thick, rounded corners, fit=(tikz@f@2)] {}; % second diagram
                         }% end of execute at end picture
                  ]
\mathbf{T}_xM\subset\R^k \rar["df_x"]
                        & \mathbf{T}_yN \subset\R^l \\
\mathbf{T}_uU=\R\A^m \rar["d\phi_u"']
                     \uar["dg_u"]
                        & \mathbf{T}_vV=\R\A^n \uar["dh_v"']
    \end{tikzcd}
\end{equation}
\end{preview}
\end{document}
  • 正如@Qrrbrbirlbel 在他的评论中所建议的,图表的名称\tikzcdmatrixname在图表末尾可用(execute at end picture执行时)。因此节点代码可以更改为:
...
    \begin{tikzcd}[...,
execute at end picture = {% <---- at each tikzcd diagram
    \node[draw=red, very thick, rounded corners, fit=(\tikzcdmatrixname)] {};
                         }% end of execute at end picture
...

编译结果与之前类似:

在此处输入图片描述

相关内容