附加符号 Tikzmark 和括号

附加符号 Tikzmark 和括号

我想知道,根据我编写代码的方式,是否可以在此示例中添加额外的符号。我提供了一个最小示例和另一张带有 + 和时间附加符号的图像。

\documentclass{article}
\usepackage{tikz,mathtools}
\usetikzlibrary{tikzmark}
\usetikzlibrary{decorations.pathreplacing}

%%% Derivative Macro

\newcommand{\der}[2]{\dfrac{d#1}{d#2}}

%%% Derivative Prime Notation

\newcommand{\pder}[2]{#1^{\prime}(#2)}


\begin{document}

\begin{align*}
 \der{}{x} [\tikzmarknode{A}{(}2x^{5}+x-1\tikzmarknode{B}{)}\tikzmarknode{C} 
 {(}3x-2\tikzmarknode{D}{)}]&=\tikzmarknode{E}{(}2x^{5}+x-1\tikzmarknode{F} 
 {)}\tikzmarknode[red]{G}{(}\textcolor{red}{3}\tikzmarknode[red]{H} 
 {)}+\tikzmarknode{I}{(}3x-2\tikzmarknode{J}{)}\tikzmarknode[red]{K} 
 {(}\textcolor{red}{10x^{4}+1}\tikzmarknode[red]{L}{)}
 \end{align*}

\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace},decorate,thick,blue]
 ([yshift=5pt]A.north) -- node[midway, above=3pt] {$f(x)$} 
 ([yshift=5pt]B.north);
\draw [decoration={brace},decorate,thick,blue]
 ([yshift=5pt]C.north) -- node[midway, above=3pt] {$g(x)$} 
  ([yshift=5pt]D.north);
 \draw [decoration={brace},decorate,thick,blue]
  ([yshift=5pt]E.north) -- node[midway, above=3pt] {$f(x)$} 
  ([yshift=5pt]F.north);
 \draw [decoration={brace},decorate,thick,red]
 ([yshift=5pt]G.north) -- node[midway, above=3pt] {$\pder{g}{x}$} 
 ([yshift=5pt]H.north);
 \draw [decoration={brace},decorate,thick,blue]
  ([yshift=5pt]I.north) -- node[midway, above=3pt] {$g(x)$} 
  ([yshift=5pt]J.north);
 \draw [decoration={brace},decorate,thick,red]
 ([yshift=5pt]K.north) -- node[midway, above=3pt] {$\pder{f}{x}$} 
 ([yshift=5pt]L.north);
 \end{tikzpicture}

 \end{document}

输出:

在此处输入图片描述

使用上面的括号,我尝试添加一些额外的操作:+ 和 \cdot

在此处输入图片描述

在代码示例中,g'(x) 稍微小一些,但如果我可以添加符号,我也可以添加空间以便稍后进行补偿。可能吗?

答案1

我实际上想说的是,定义一种样式,只插入带有节点的括号路径,而不是有那么多分散的\tikzmarknodes,这更符合人体工程学。这个答案附带一种overbrace样式,可以用作

\draw[blue,thick,overbrace={A 其中 {$f(x)$} 称为 f1}];

A您想要过度支撑的节点在哪里,{$f(x)$}顶部的节点在哪里以及f1它的名称在哪里。然后插入附加符号也会容易得多。

\documentclass{article}
\usepackage{tikz,mathtools}
\usetikzlibrary{tikzmark}
\usetikzlibrary{decorations.pathreplacing,calc}

%%% Derivative Macro

\newcommand{\der}[2]{\dfrac{\mathrm{d}#1}{\mathrm{d}#2}}

%%% Derivative Prime Notation

\newcommand{\pder}[2]{#1^{\prime}(#2)}

\tikzset{overbrace/.style args={#1 with #2 called #3}{
insert path={[decoration={brace},decorate] ([yshift=5pt]#1.north west)
--  node[midway, above=3pt] (#3) {#2}  
([yshift=5pt]#1.north east) }
}}

\begin{document}

\begin{align*}
 \der{}{x} [\tikzmarknode{A}{(2x^{5}+x-1)}
 \tikzmarknode{B}{\vphantom{x^{5}}(3x-2)}]
 &=\tikzmarknode{C}{(2x^{5}+x-1)}
 \tikzmarknode[red]{D}{\vphantom{x^{5}}(3H)}
 +\tikzmarknode{E}{\vphantom{x^{5}}(3x-2)}
 \tikzmarknode[red]{F}{(10x^{4}+1)}
 \end{align*}

\begin{tikzpicture}[overlay, remember picture]
\draw[blue,thick,overbrace={A with {$f(x)$} called f1}];
\draw[blue,thick,overbrace={B with {$g(x)$} called g1}];
\draw[blue,thick,overbrace={C with {$f(x)$} called f2}];
\draw[red,thick,overbrace={D with {$\pder{g}{x}$} called dg1}];
\draw[blue,thick,overbrace={E with {$g(x)$} called g2}];
\draw[red,thick,overbrace={F with {$\pder{f}{x}$} called df1}];
\path ($(A.east)!0.5!(B.west)$) coordinate (auxAB)
($(C.east)!0.5!(D.west)$) coordinate (auxCD)
($(D.east)!0.5!(E.west)$) coordinate (auxDE)
($(E.east)!0.5!(F.west)$) coordinate (auxEF);
\path (auxAB|-f1) node[blue]{$\cdot$}
([xshift=-3pt]auxCD|-f1) node[blue]{$\cdot$} %manual correction
(auxDE|-f1) node[blue]{$+$}
(auxEF|-f1) node[blue]{$\cdot$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

如果你想要调整括号的布局,你只需要调整样式。例如,如果你想让括号之间有间隙,你可以这样做

\tikzset{overbrace/.style args={#1 with #2 called #3}{
insert path={[decoration={brace},decorate] ([yshift=5pt,xshift=1pt]#1.north west)
--  node[midway, above=3pt] (#3) {#2}  
([yshift=5pt,xshift=-1pt]#1.north east) }
}}

得出

在此处输入图片描述

还要注意的是,我将符号放在了底层方程符号的上方。如果你想将它们放在中间,这会更容易。

\documentclass{article}
\usepackage{tikz,mathtools}
\usetikzlibrary{tikzmark}
\usetikzlibrary{decorations.pathreplacing}

%%% Derivative Macro

\newcommand{\der}[2]{\dfrac{\mathrm{d}#1}{\mathrm{d}#2}}

%%% Derivative Prime Notation

\newcommand{\pder}[2]{#1^{\prime}(#2)}

\tikzset{overbrace/.style args={#1 with #2 called #3}{
insert path={[decoration={brace},decorate] ([yshift=5pt,xshift=1pt]#1.north west)
--  node[midway, above=3pt] (#3) {#2}  
([yshift=5pt,xshift=-1pt]#1.north east) }
}}

\begin{document}

\begin{align*}
 \der{}{x} [\tikzmarknode{A}{(2x^{5}+x-1)}
 \tikzmarknode{B}{\vphantom{x^{5}}(3x-2)}]
 &=\tikzmarknode{C}{(2x^{5}+x-1)}
 \tikzmarknode[red]{D}{\vphantom{x^{5}}(3)}
 +\tikzmarknode{E}{\vphantom{x^{5}}(3x-2)}
 \tikzmarknode[red]{F}{(10x^{4}+1)}
 \end{align*}

\begin{tikzpicture}[overlay, remember picture]
\draw[blue,thick,overbrace={A with {$f(x)$} called f1}];
\draw[blue,thick,overbrace={B with {$g(x)$} called g1}];
\draw[blue,thick,overbrace={C with {$f(x)$} called f2}];
\draw[red,thick,overbrace={D with {$\pder{g}{x}$} called dg1}];
\draw[blue,thick,overbrace={E with {$g(x)$} called g2}];
\draw[red,thick,overbrace={F with {$\pder{f}{x}$} called df1}];
\path[blue] (f1) -- (g1) node[midway] {$\cdot$}
(f2) -- (dg1)  node[midway] {$\cdot$}
(dg1) -- (g2)  node[midway] {$+$}
(g2) -- (df1)  node[midway] {$\cdot$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

尽管 tikz 是一款非常强大的工具,但对于某些任务来说成本太高。在这里,我使用了\overbrace一个小技巧来添加运算符,同时0pt使用宏占用宽度。此外,正如 @LoopSpace 所建议的,我们可以通过在不带该术语的括号中 \makebox[0pt]{..}添加括号来使括号处于相同的高度。\vphantom{x^5}

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\newcommand{\hide}[2]{\makebox[0pt][l]{$\hspace{#1pt}#2$}}

\[
\frac{d}{dx}[\overbrace{(2x^5+x-1)}^{f(x)\hide{20}{\cdot}} \overbrace{(\vphantom{x^5}3x-2)}^{g(x)}]
= \overbrace{(2x^5+x-1)}^{f(x)\hide{15}{\cdot}} \overbrace{(\vphantom{x^5}3)}^{g'(x)\hide{2}{+}} 
+ \overbrace{(\vphantom{x^5}3x-2)}^{g(x)\hide{10}{\cdot}} \overbrace{(10x^4+1)}^{f'(x)}
\]

\end{document}

在此处输入图片描述

答案3

为了好玩,使用\overbrace命令和另一个简单的解决方案pstricks

\documentclass{article}
\usepackage{mathtools, esdiff}
\usepackage{pst-node}

\begin{document}

\begin{align*}
 \diff{}{x}\bigl[(\textcolor{red}{\overbrace{\strut\color{black}2x^{5}+x-1}^{\Rnode{f}{\textstyle f(x)}} \textcolor{black}{ )(}\overbrace{\strut\color{black}3x-2}^{\Rnode{g}{\textstyle g(x)}}})\bigr] &= (\textcolor{blue}{\overbrace{\color{black}2x^{5}+x-1}^{\Rnode{bluef}{\textstyle f(x})}})\textcolor{red}{\overbrace{\strut(3)}^{\Rnode{dg}{\textstyle g'(x)}} }+ (\textcolor{blue}{\overbrace{\strut\color{black}3x-2}^{\Rnode{blueg}{\textstyle g(x)}}} )\textcolor{red}{(\overbrace{10x^{4}+1}^{\Rnode{df}{\textstyle f'(x )}})}%
 %% Additional symbols
 \psset{linestyle=none}
 \ncline{f}{g}\ncput{\boldsymbol\cdot}
 \ncline{bluef}{dg}\ncput{\boldsymbol\cdot}
 \ncline{blueg}{df}\ncput{\boldsymbol\cdot}
 \ncline{blueg}{dg}\ncput{ + }
 \end{align*}

 \end{document} 

在此处输入图片描述

相关内容