如何在tikz中可变大小的节点后绘制括号

如何在tikz中可变大小的节点后绘制括号

我有一种方法可以在文章中表示函子。为此,我使用以下代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}


\begin{document}


\begin{tikzpicture}[>=stealth]
\draw[->] (2,0)--(4,0);
\draw[->] (1.2,-1.26)--(1.2,-2.8);
\draw[->]  (4.8,-1.26)--(4.8,-2.8);
\draw[|->] (2,-1)--(3.6,-1);
\draw[|->] (2,-2)--(3.6,-2);
\draw[|->] (2,-3)--(3.6,-3);
\node at (0, 0) {${F}:$};
\node at (1.2, 0) {${\mathbf{Top}}$};
\node at (4.8, 0) {${\mathbf{Set}}$};
\node at (1.2, -1) {${(X, \tau)}$};
\node at (1.2, -3) {${(Y, \sigma)}$};
\node at (1, -2) {${f}$};
\node at (4.8, -1) {${X}$};
\node at (4.8, -3) {${Y}$};
\node at (5.4, -2) {${f}$}; 

\draw[decoration={brace,mirror,raise=6pt},decorate,line width=1pt]
(5.6,-3.2)--(5.6,-0.8);
\draw[decoration={brace,mirror,raise=6pt},decorate, line width=1.2pt]
(6,-3.2)--(6,0.2); 
\end{tikzpicture}
\end{document}

这样就可以绘制图片了。但是每次我都必须重新执行此操作,因此我想使用\newcommandLaTeX 将其作为模板。当我尝试这样做时,如何确保括号不与其左侧的节点重叠?注意:节点的宽度可以变化,具体取决于类别的对象。

答案1

一个快速的答案只是为了完成你的工作,你可以使用其他字体的字体大小来调整它或添加更多参数

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}

%Rightbrace draws a right brace right of #2 (up point) and #3 (down point) at
% distance of #1 (xshift) and with line width #4
\newcommand{\rightbrace}[4][0pt]{\draw[decoration={brace,mirror,raise=6pt},decorate,line width=#4] ($(#2)+(#1,-0.2)$)--($(#3)+(#1,0.2)$);}
\begin{document}


  \begin{tikzpicture}[>=stealth]
   \draw[->] (2,0)--(4,0);
   \draw[->] (1.2,-1.26)--(1.2,-2.8);
   \draw[->]  (4.8,-1.26)--(4.8,-2.8);
   \draw[|->] (2,-1)--(3.6,-1);
   \draw[|->] (2,-2)--(3.6,-2);
   \draw[|->] (2,-3)--(3.6,-3);
   \node at (0, 0) {${F}:$};
   \node at (1.2, 0) {${\mathbf{Top}}$};
   \node (C) at (4.8, 0) {${\mathbf{Set}}$};
   \node at (1.2, -1) {${(X, \tau)}$};
   \node at (1.2, -3) {${(Y, \sigma)}$};
   \node at (1, -2) {${f}$};
   \node (A) at (4.8, -1) {${X}$};
   \node (B) at (4.8, -3) {${Y}$};
   \node at (5.4, -2) {${f}$};

   \rightbrace[0.8]{B}{A}{1pt}
   %\draw[decoration={brace,mirror,raise=6pt},decorate,line width=1pt] (5.6,-3.2)--(5.6,-0.8);
   \rightbrace[1.2]{B}{C}{1pt}
   %\draw[decoration={brace,mirror,raise=6pt},decorate, line width=1.2pt](6,-3.2)--(6,0.2); 
  \end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

相关内容