我有当前的 tikz 图片,并且想在第二行和第三行之间两个向下箭头未标识的位置添加一个下支撑。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing, matrix, arrows}
\begin{document}
\begin{tikzpicture}[>=angle 90]
\matrix(a)[matrix of math nodes,
column sep=-5pt,
% row sep=-5pt,
text height=1ex]
{ y = & x^2 & -5x & +6 & \qquad & & & \frac{1}{2}(-5)=\frac{-5}{2} \\
y = & x^2 & -5x &+\frac{25}{4} & - \frac{25}{4}&+6 & \qquad & & \left(\frac{-5}{2}\right)^2=\frac{25}{4} \\
& & & \hspace{1pt} & \\
y=& (x &-&\frac{5}{2}&)^2 -\frac{1}{4} &\\};
\path[->](a-2-9) edge [bend left=20] (a-2-4);
\path[->](a-2-9) edge [bend left=20] (a-2-5);
\path[->](a-1-8) edge [bend left=50] (a-4-4);
\path[->](a-2-2) edge [out=270,in=90] (a-4-3);
\path[->](a-2-3) edge [out=270,in=90] (a-4-3);
\end{tikzpicture}
\end{document}
下图中我想把红色旁边的箭头改成下括号:
答案1
这里没有什么特别的,因为你可以访问矩阵中节点的锚点,所以你只需要
\draw[red,decorate,decoration={brace,mirror,raise=-2pt}]
([xshift=3pt]a-2-2.south west) -- ([xshift=-5pt]a-2-3.south east);
或者
\draw[red,decorate,decoration={brace,mirror,raise=-2pt}]
([xshift=3pt]a-2-2.south west) -- ([xshift=-4pt]{a-2-3.south east|-a-2-2.south west});
以保证支架完全水平。
完整代码(我做了一些其他可选的更改):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing, matrix, arrows}
\begin{document}
\begin{tikzpicture}[>=angle 90]
\matrix (a) [
matrix of math nodes,
column sep=-5pt,
%row sep=-5pt,
text height=1ex
]
{
y = & x^2 & -5x & +6 & \qquad & & & \frac{1}{2}(-5)=\frac{-5}{2} \\
y = & x^2 & -5x &+\frac{25}{4} & - \frac{25}{4}&+6 & \qquad
& & \left(\frac{-5}{2}\right)^2=\frac{25}{4} \\
& & & & \\[8pt]
y=& (x &-&\frac{5}{2})^2 & -\frac{1}{4} &\\
};
\path[->]
(a-2-9) edge [bend left=20] (a-2-4)
(a-2-9) edge [bend left=20] (a-2-5)
(a-1-8) edge [bend left=50] (a-4-4)
(a-2-2) edge [out=270,in=90] (a-4-3)
(a-2-3) edge [out=270,in=90] (a-4-3);
\draw[red,decorate,decoration={brace,mirror,raise=-2pt}]
([xshift=3pt]a-2-2.south west) -- ([xshift=-4pt]{a-2-3.south east|-a-2-2.south west});
\end{tikzpicture}
\end{document}
但是请注意,上述解决方案中的间距是错误的且不一致的(仔细查看运算符周围,您会看到这一点)。我建议您采用另一种方法。使用align*
(或alignat*
)来amsmath
编写方程式,然后借助 TikZ 库tikzmark
放置一些稍后用于绘制括号和箭头的标记:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing, matrix, arrows,tikzmark}
\begin{document}
\begin{align*}
y &= x^2 -5x +6 & -5\Bigl(\tikzmark{startc}\frac{1}{2}\Bigr) &= \frac{-5}{2} \\[10pt]
y &= \tikzmark{starta}x^2 - 5x\tikzmark{enda} + \frac{25}{\tikzmark{endbi}4}
- \frac{25}{\tikzmark{endbii}4} +6 & \Bigl(\frac{-5}{2}\Bigr)^2
&= \tikzmark{startb}\frac{25}{4} \\[10pt]
y &= \Bigl(x - \frac{5}{\tikzmark{endc}2} \Bigr)^2 -\frac{1}{4}
\end{align*}
\begin{tikzpicture}[remember picture,overlay]
\draw[red,decorate,decoration={brace,mirror,raise=2pt}]
(pic cs:starta) -- (pic cs:enda);
\path[->]
(pic cs:startb) edge [bend left=20] ([shift={(5pt,-3pt)}]pic cs:endbi)
(pic cs:startb) edge [bend left=20] ([shift={(5pt,-3pt)}]pic cs:endbii)
([shift={(5pt,-8pt)}]pic cs:startc) edge [bend left=20] ([shift={(5pt,-3pt)}]pic cs:endc);
\end{tikzpicture}
\end{document}
结果: