我正在寻找一种方法来突出显示我生成的 TikZ 图形中的特定区域。更具体地说,我有一个 TikZ 图形,说明有两个八面体。在我第一次展示这个图形之后,我想在稍后更详细地讨论特定概念时在我的文档中重复使用它。为了清楚地说明讨论了图形的哪个概念,我想突出显示图形的第一个和第二个八面体。有没有简单的方法可以做到这一点?
图表如下
\begin{tikzcd}
{a_{0,1}} \arrow[r, "{e_{0,1,2}}"] & {a_{0,2}} \arrow[r, "{e_{0,2,3}}"] \arrow[d, "{e_{2,0,1}}"] & {a_{0,3}} \arrow[r, "{e_{0,3,4}}"] \arrow[d, "{e_{3,0,1}}"] & {a_{0,4}} \arrow[d, "{e_{4,0,1}}"] & \\
& {a_{1,2}} \arrow[r, "{e_{1,2,3}}"] \arrow[lu, squiggly] & {a_{1,3}} \arrow[r, "{e_{1,3,4}}"] \arrow[d, "{e_{3,1,2}}"] & {a_{1,4}} \arrow[d, "{e_{4,1,2}}"] \arrow[r, "{e_{1,0,4}}"] & {a_{0,1}[1]} \arrow[d] \\
& & {a_{2,3}} \arrow[r, "{e_{2,3,4}}"] \arrow[lu, squiggly] & {a_{2,4}} \arrow[d, "{e_{4,2,3}}"] \arrow[r, "{e_{2,0,4}}"] & {a_{0,2}[1]} \arrow[d] \\
& & & {a_{3,4}} \arrow[lu, squiggly] \arrow[r, "{e_{3,0,4}}"] & {a_{0,3}[1]} \arrow[d] \\
& & & & {a_{0,4}[1]} \arrow[lu, squiggly]
\end{tikzcd}\]
I want to highlight the first octahedral which is the following
\[\begin{tikzcd}
a_{01} \arrow[r] & a_{02} \arrow[r] \arrow[d] & a_{03} \arrow[d] & \\
& a_{12} \arrow[r] \arrow[lu,squiggly] & a_{13} \arrow[d] \arrow[r] & {a_{01}[1]} \arrow[d] \\
& & a_{23} \arrow[lu,squiggly] \arrow[r] & {a_{02}[1] } \arrow[d] \\
& & & {a_{03}[1]} \arrow[lu,squiggly]
\end{tikzcd}\]
答案1
通过检查tikz-cd
的实现tikzlibrarycd.code.tex
,我了解到以下事实:
- 环境
tikzcd
目前是一个tikzpicture
环境 tikzcd
的环境内容被包裹在里面\matrix[matrix of (math) nodes]\bgroup <env content> \egroup;
。- in
<opt-arg>
被\begin{tikzcd}[<opt-arg>]
传递给tikzpicture
。
因此可以先给矩阵命名,然后在图尾添加绘制代码,这样就可以绘制一个框架了。有两种绘制框架的方式,分别是\node[draw, fit=<list of nodes>] {};
和 普通\draw
。
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing, fit}
\begin{document}
\[\begin{tikzcd}[
every matrix/.append style={name=mtx},
execute at end picture={
\node[fit=(mtx-1-1) (mtx-3-3), draw=red] {};
\draw[blue] (mtx-2-5.north west) rectangle (mtx-4-5.south east);
}]
{a_{0,1}} \arrow[r, "{e_{0,1,2}}"]
& {a_{0,2}} \arrow[r, "{e_{0,2,3}}"] \arrow[d, "{e_{2,0,1}}"]
& {a_{0,3}} \arrow[r, "{e_{0,3,4}}"] \arrow[d, "{e_{3,0,1}}"]
& {a_{0,4}} \arrow[d, "{e_{4,0,1}}"]
\\
& {a_{1,2}} \arrow[r, "{e_{1,2,3}}"] \arrow[lu, squiggly]
& {a_{1,3}} \arrow[r, "{e_{1,3,4}}"] \arrow[d, "{e_{3,1,2}}"]
& {a_{1,4}} \arrow[d, "{e_{4,1,2}}"] \arrow[r, "{e_{1,0,4}}"]
& {a_{0,1}[1]} \arrow[d]
\\
&
& {a_{2,3}} \arrow[r, "{e_{2,3,4}}"] \arrow[lu, squiggly]
& {a_{2,4}} \arrow[d, "{e_{4,2,3}}"] \arrow[r, "{e_{2,0,4}}"]
& {a_{0,2}[1]} \arrow[d]
\\
&
&
& {a_{3,4}} \arrow[lu, squiggly] \arrow[r, "{e_{3,0,4}}"]
& {a_{0,3}[1]} \arrow[d]
\\
&
&
&
& {a_{0,4}[1]} \arrow[lu, squiggly]
\end{tikzcd}\]
I want to highlight the first octahedral which is the following
\[\begin{tikzcd}
a_{01} \arrow[r]
& a_{02} \arrow[r] \arrow[d]
& a_{03} \arrow[d]
\\
& a_{12} \arrow[r] \arrow[lu,squiggly]
& a_{13} \arrow[d] \arrow[r]
& {a_{01}[1]} \arrow[d]
\\
&
& a_{23} \arrow[lu,squiggly] \arrow[r]
& {a_{02}[1] } \arrow[d]
\\
&
&
& {a_{03}[1]} \arrow[lu,squiggly]
\end{tikzcd}\]
\end{document}