嵌套的 Tikzpictures

嵌套的 Tikzpictures

我怎样才能编写一个程序来命名每张图片,以便我可以使用 tikzpicture 环境一次。

我对输出很满意,但对程序不满意

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
\node at (-5,1) {$
\begin{tikzpicture}[scale=.75]
\draw[<->,thick]
    (4,0) coordinate (A) node[right] {}
    -- (0,0) coordinate (O) node[left] {}
    -- (0,4) coordinate (B) node[above right] {}
    pic["\textcolor{red}{\ \ $90^{\circ}$}", draw=red, ->, angle eccentricity=1.2, angle radius=1cm]
    {angle=A--O--B};
\node at (0,-.5) [right] {Right angle};
\draw[thick] (.25,0)--(.25,.25)--(0,.25);
\draw[fill] (0,0) circle (2pt);
\end{tikzpicture}$};

\node at (0,0) {$\begin{tikzpicture}[scale=.75]
\draw[<->,thick]
    (4,0) coordinate (A) node[right] {}
    -- (0,0) coordinate (O) node[left] {}
    -- (-4,0) coordinate (B) node[above right] {}
    pic["\textcolor{red}{\ \ $180^{\circ}$}", draw=red, ->, angle eccentricity=1.2, angle radius=1cm]
    {angle=A--O--B};
\node at (0,-.5) [] {Straight angle};
%\draw[thick] (.25,0)--(.25,.25)--(0,.25);
\draw[fill] (0,0) circle (2pt);
\end{tikzpicture}$};

\node at (6,0) {$\begin{tikzpicture}[scale=.75]
\draw[<->,thick]
    (4,0) coordinate (A) node[right] {}
    -- (0,0) coordinate (O) node[left] {}
    -- (3,2) coordinate (B) node[above right] {}
    pic["\textcolor{red}{$\theta$}", draw=red, ->, angle eccentricity=1.2, angle radius=1cm]
    {angle=A--O--B};
\node at (-.5,-.5) [right] {Acute angle $0 < \theta < 90^{\circ}$};
%\draw[thick] (.25,0)--(.25,.25)--(0,.25);
\draw[fill] (0,0) circle (2pt);
\end{tikzpicture}$};

\node at (0,-3) {$
\begin{tikzpicture}[scale=.75]
\draw[<->,thick]
    (3,0) coordinate (A) node[right] {}
    -- (0,0) coordinate (O) node[left] {}
    -- (-3,2) coordinate (B) node[above right] {}
    pic["\textcolor{red}{$\theta$}", draw=red, ->, angle eccentricity=1.2, angle radius=1cm]
    {angle=A--O--B};
\node at (-1.5,-.5) [right] {Obtuse angle\ $90^{\circ} < \theta < 180^{\circ}$};
%\draw[thick] (.25,0)--(.25,.25)--(0,.25);
\draw[fill] (0,0) circle (2pt);
\end{tikzpicture}$};
\end{tikzpicture} 
\end{center}
\caption{}
\end{figure}

在此处输入图片描述

答案1

这是实现此目的的方法。按键:

  1. 提供完整的 MWE。使用此清单到达那里。

  2. \pic在本例中,定义并将参数传递给 new diagr。传递多少参数以及它们的含义由您决定。以下是其中一种方法:

        pics/diagr/.style args={#1/#2/#3} {
            code={
...
            }}
  1. \pic根据需要放置这个新的类似节点,同时在“文本字段”中传递名称和参数{}
    \pic at (0,0)   {diagr={90/90^{\circ}/Right angle}};
  1. 至少对于点最好使用极坐标(B)

  2. 如果需要矩形的正方形,请定义并传递一个新参数,或者使用ifthen内部的包diagr

结果

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,arrows.meta}

\begin{document}

 \begin{figure}[h]
%   \begin{center}
    \centering
    \begin{tikzpicture}[
        % IF you need to scale it; alternative: adjust drawing itself
        scale=0.8,transform shape,
        % nicer arrow tips
        >={Stealth},
        % #1 = angle value
        % #2 = anle symbol
        % #3 = "caption"
        pics/diagr/.style args={#1/#2/#3} {
            code={
                \draw[<->,thick]
                    ( 0:3) coordinate (A) node[right] {} -- 
                    ( 0,0) coordinate (O) node[left] {} -- 
                    (#1:3) coordinate (B) node[above right] {}
                    pic[
                        "\textcolor{red}{$#2$}", 
                        draw=red,
                        ->, 
                        angle eccentricity=1.3,
                        angle radius=1cm
                    ]
                    {angle=A--O--B};
                \node at (-1.5,-.5) [right] {#3};
                \draw[fill] (0,0) circle (2pt);     
            }
        }
    ]
    
    \pic at (0,0)   {diagr={90/90^{\circ}/Right angle}};
    \pic at (7,0)   {diagr={180/180^{\circ}/Straight angle}};
    \pic at (12,0)  {diagr={40/\theta/Acute angle\ $90^{\circ} < \theta < 90^{\circ}$}};
    \pic at (7,-5)  {diagr={120/\theta/Obtuse angle\ $90^{\circ} < \theta < 180^{\circ}$}};

     \end{tikzpicture}

%   \end{center}
 \caption{Captain caption}
 \end{figure}

\end{document}

相关内容