声明 TikZ 风格(仅一次!)

声明 TikZ 风格(仅一次!)

在此链接中我发现了一个非常漂亮的\tikzset。在我正在写的一本书中,我多次使用了它錄音編輯。是否有办法\begin...\end{tikzpicture}用这个 tikzset 创建?例如,我有这个(长)代码。

\PassOptionsToPackage{svgnames, x11names}{xcolor}
\documentclass{article}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{stix}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usepackage[bb=ams]{mathalpha}
\usepackage{extarrows}

\begin{document}

\begin{center}
\begin{tikzpicture}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(.2,0) -- (3,1) arc (0:180:1.4 and 1) -- cycle
(4,1) circle(.8)
(6,1) ellipse(.5 and 1)
(0,3) to [bend left] (3,4)
(4,3) rectangle (6,4);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(0,0) rectangle (2,2) (0,2) -- (2,0) (7,0) -- (7,2) -- (9,0) -- (7,0) (8,2) -- (10,2) -- (10,0) (8,2) -- (10,0);
\node at (-.25,1) {\(a\)};
\node at (2.25,1) {\(a\)};
\node at (1,2.25) {\(u\)};
\node at (1,-.25) {\(v\)};
\node at (-1.5,1) {\Huge{\(P_{w'}=\)}};
\node at (4.5,1) {\huge{\(\xRightarrow[\text{la diagonale}]{\text{tagliando lungo}}\)}};
\node at (6.75,1) {\(a\)};
\node at (10.25,1) {\(a\)};
\node at (9,2.25) {\(u\)};
\node at (8,-.25) {\(v\)};
\node at (8,1.35) {\(b\)};
\node at (9,0.65) {\(b\)};
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(0,0) circle (1cm) (4.5,-1) -- (4.5,1) -- (2.5,1) (4.5,-1) -- (2.5,-1) -- (2.5,1) (6,0) -- (7,1) -- (8,1) -- (9,0) (6,0) -- (7,-1) -- (8,-1) -- (9,0);
\node at (0,1.25) {\(a\)};
\node at (0,-1.25) {\(a\)};
\node at (6.5,.75) {\(a\)};
\node at (7.5,1.25) {\(a\)};
\node at (2.25,0) {\(b\)};
\node at (3.5,1.25) {\(c\)};
\node at (4.75,0) {\(b\)};
\node at (3.5,-1.25) {\(c\)};
\node at (8.5,.75) {\(b\)};
\node at (8.5,-.75) {\(c\)};
\node at (7.5,-1.25) {\(b\)};
\node at (6.5,-.75) {\(c\)};
\node at (0,-2) {\(a^+a^+\)};
\node at (3.5,-2) {\(b^+c^-b^-c^+\)};
\node at (7.5,-2) {\(a^+a^+b^+c^+b^-c^-\)};
\node at (1.5,0) {\huge{\#}};
\node at (5.5,0) {\huge{$\cong$}};
\draw[dashed, -latex, shorten >= 3pt] (7,1) -- (7.75,-.5);
\draw[dashed] (7,1) -- (8,-1);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(1,-1) -- (0,0) -- (1,1) -- (2,1) -- (3,0) -- (2,-1) -- (1,-1) (5,-1) -- (4,0) -- (5,1) -- (6,1) -- (7,0) -- (6,-1) -- (5,-1);
\node at (1.5,-1.25) {\(b\)};
\node at (0.375,-0.625) {\(c\)};
\node at (0.375,.625) {\(d\)};
\node at (1.5,1.25) {\(c\)};
\node at (2.675,0.625) {\(b\)};
\node at (2.675,-.625) {\(d\)};

\node at (5.5,-1.25) {\(e\)};
\node at (4.375,-0.625) {\(e\)};
\node at (4.375,.625) {\(f\)};
\node at (5.5,1.25) {\(f\)};
\node at (6.675,0.625) {\(g\)};
\node at (6.675,-.625) {\(g\)};
\node at (3.5,0) {\huge{$\cong$}};
\end{tikzpicture}
\end{center}

\end{document}

我自己的目标是创建一个简化的代码,在其中的一部分(可能是第一部分......)我很快声明了\tikzstyle另一部分(用 tikzset 分隔)。可以吗?非常感谢

答案1

没有必要\tikzset在每张图片中重复这个命令。你可以在文档的前言中放置一次调用,然后所有图片都可以使用它:

\PassOptionsToPackage{svgnames, x11names}{xcolor}
\documentclass{article}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{stix}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usepackage[bb=ams]{mathalpha}
\usepackage{extarrows}
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}
\begin{document}

\begin{center}
\begin{tikzpicture}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(.2,0) -- (3,1) arc (0:180:1.4 and 1) -- cycle
(4,1) circle(.8)
(6,1) ellipse(.5 and 1)
(0,3) to [bend left] (3,4)
(4,3) rectangle (6,4);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}

\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(0,0) rectangle (2,2) (0,2) -- (2,0) (7,0) -- (7,2) -- (9,0) -- (7,0) (8,2) -- (10,2) -- (10,0) (8,2) -- (10,0);
\node at (-.25,1) {\(a\)};
\node at (2.25,1) {\(a\)};
\node at (1,2.25) {\(u\)};
\node at (1,-.25) {\(v\)};
\node at (-1.5,1) {\Huge{\(P_{w'}=\)}};
\node at (4.5,1) {\huge{\(\xRightarrow[\text{la diagonale}]{\text{tagliando lungo}}\)}};
\node at (6.75,1) {\(a\)};
\node at (10.25,1) {\(a\)};
\node at (9,2.25) {\(u\)};
\node at (8,-.25) {\(v\)};
\node at (8,1.35) {\(b\)};
\node at (9,0.65) {\(b\)};
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(0,0) circle (1cm) (4.5,-1) -- (4.5,1) -- (2.5,1) (4.5,-1) -- (2.5,-1) -- (2.5,1) (6,0) -- (7,1) -- (8,1) -- (9,0) (6,0) -- (7,-1) -- (8,-1) -- (9,0);
\node at (0,1.25) {\(a\)};
\node at (0,-1.25) {\(a\)};
\node at (6.5,.75) {\(a\)};
\node at (7.5,1.25) {\(a\)};
\node at (2.25,0) {\(b\)};
\node at (3.5,1.25) {\(c\)};
\node at (4.75,0) {\(b\)};
\node at (3.5,-1.25) {\(c\)};
\node at (8.5,.75) {\(b\)};
\node at (8.5,-.75) {\(c\)};
\node at (7.5,-1.25) {\(b\)};
\node at (6.5,-.75) {\(c\)};
\node at (0,-2) {\(a^+a^+\)};
\node at (3.5,-2) {\(b^+c^-b^-c^+\)};
\node at (7.5,-2) {\(a^+a^+b^+c^+b^-c^-\)};
\node at (1.5,0) {\huge{\#}};
\node at (5.5,0) {\huge{$\cong$}};
\draw[dashed, -latex, shorten >= 3pt] (7,1) -- (7.75,-.5);
\draw[dashed] (7,1) -- (8,-1);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\path [draw=blue,postaction={on each segment={mid arrow=red}}]
(1,-1) -- (0,0) -- (1,1) -- (2,1) -- (3,0) -- (2,-1) -- (1,-1) (5,-1) -- (4,0) -- (5,1) -- (6,1) -- (7,0) -- (6,-1) -- (5,-1);
\node at (1.5,-1.25) {\(b\)};
\node at (0.375,-0.625) {\(c\)};
\node at (0.375,.625) {\(d\)};
\node at (1.5,1.25) {\(c\)};
\node at (2.675,0.625) {\(b\)};
\node at (2.675,-.625) {\(d\)};

\node at (5.5,-1.25) {\(e\)};
\node at (4.375,-0.625) {\(e\)};
\node at (4.375,.625) {\(f\)};
\node at (5.5,1.25) {\(f\)};
\node at (6.675,0.625) {\(g\)};
\node at (6.675,-.625) {\(g\)};
\node at (3.5,0) {\huge{$\cong$}};
\end{tikzpicture}
\end{center}

\end{document}

相关内容