在 tikz 中在角度标签周围添加空格

在 tikz 中在角度标签周围添加空格

在下图中,我想在$\theta$角度标签周围添加一些空白(类似于$L_1$$L_2$标签的显示方式)。我使用anglesquotestikz 库来创建角度。

\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{positioning, angles, quotes}

\begin{document}

\begin{center}
\begin{tikzpicture} 
    \draw [domain=-4:94] plot ({4*cos(\x)},{4*sin(\x)});
    \draw[-] (-0.5,0) -- (4.5,0) coordinate (x);
    \draw[-] (0,-0.5) -- (0,4.5);

    \draw[-] (0,0) coordinate (O) -- node[fill=white] {$L_1$} ({4.5*cos(10)},{4.5*sin(10)}) coordinate (L1);
    \draw[-] (0,0) -- node[fill=white] {$L_2$} ({4.5*cos(70)},{4.5*sin(70)}) coordinate (L2);
    \draw[-] (0,0) -- ({4.5*cos(60)},{4.5*sin(60)}) coordinate (L);

    \draw ({4*cos(10)},{4*sin(10)}) circle (0.69724594);
    \draw ({4*cos(70)},{4*sin(70)}) circle (0.69724594);

    \filldraw
        (0,0) circle (1.5pt)
        (4,0) circle (1.5pt)
        ({4*cos(10)},{4*sin(10)}) circle (1.5pt)
        ({4*cos(60)},{4*sin(60)}) circle (1.5pt)
        ({4*cos(70)},{4*sin(70)}) circle (1.5pt);
    
    \pic [draw, <->,angle radius=17mm, angle eccentricity=1,"$\theta$"] {angle = x--O--L};
    \pic [draw, <->, angle radius=10mm, angle eccentricity=1,"$\theta$"] {angle = L1--O--L2};
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

答案1

pic text options允许您指定图片特定的选项,这里我用白色填充了背景pic text options={fill=white,text=red}

我擅自用不同的颜色来表示各个角度,在我看来,这使得图形更容易阅读:draw=red

使用quotes库,只需编写"$\theta$"{fill=white,text=red,inner sep=1pt}而不是"$\theta$",pic text options={fill=white,text=red}

截屏

\documentclass[border=5mm,tikz]{standalone}
\usepackage{amsthm}
%\usepackage{tikz}
\usetikzlibrary{positioning, angles, quotes}

\begin{document}

%\begin{center}
\begin{tikzpicture} 
    \draw [domain=-4:94] plot ({4*cos(\x)},{4*sin(\x)});
    \draw[-] (-0.5,0) -- (4.5,0) coordinate (x);
    \draw[-] (0,-0.5) -- (0,4.5);

    \draw[-] (0,0) coordinate (O) -- node[fill=white] {$L_1$} ({4.5*cos(10)},{4.5*sin(10)}) coordinate (L1);
    \draw[-] (0,0) -- node[fill=white] {$L_2$} ({4.5*cos(70)},{4.5*sin(70)}) coordinate (L2);
    \draw[-] (0,0) -- ({4.5*cos(60)},{4.5*sin(60)}) coordinate (L);

    \draw ({4*cos(10)},{4*sin(10)}) circle (0.69724594);
    \draw ({4*cos(70)},{4*sin(70)}) circle (0.69724594);

    \filldraw
        (0,0) circle (1.5pt)
        (4,0) circle (1.5pt)
        ({4*cos(10)},{4*sin(10)}) circle (1.5pt)
        ({4*cos(60)},{4*sin(60)}) circle (1.5pt)
        ({4*cos(70)},{4*sin(70)}) circle (1.5pt);
    
    \pic [draw=red, <->,angle radius=17mm, angle eccentricity=1,"$\theta$",pic text options={fill=white,text=red}] {angle = x--O--L};
    \pic [draw=blue, <->, angle radius=10mm, angle eccentricity=1,"$\theta$",pic text options={fill=white,text=blue}] {angle = L1--O--L2};
\end{tikzpicture}
%\end{center}

\end{document}

答案2

quotes使用库和极坐标的另一个选项:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{angles, 
                arrows.meta,
                positioning, 
                quotes}

\begin{document}
    \begin{tikzpicture}[
              dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt,
                            node contents={}},
every edge quotes/.style = {fill=white, inner sep=2pt, anchor=center},
                       > = {Straight Barb[angle=60:2pt 3]},
    my angle/.style args = {#1/#2}{draw=#1, <->, 
                                   angle radius = #2,
                                   angle eccentricity=1,
                                   font=\small, text=#1,
                                   inner sep=1pt},
                        ]
% coordinates
    \draw[-] (-0.5,0) -- (4.5,0) coordinate (x);
    \draw[-] (0,-0.5) -- (0,4.5);
% arc
\draw   (-4:4) arc (-4:94:4);
% rays
\draw   (0,0) node (O) [dot] to["$L_1$"] (10:4.5) coordinate (L1);
\draw   (O) to["$L_2$"] (70:4.5) coordinate (L2);
\draw   (O) -- (60:4.5) coordinate (L);
% small circles
\draw   (10:4)  circle (0.69724594)
        (70:4)  circle (0.69724594);
% angles
\pic [my angle=red/15mm, "$\theta_1$" fill=white] {angle = x--O--L};
\pic [my angle=blue/10mm,"$\theta_2$" fill=white] {angle = L1--O--L2};
% dots    
\foreach \angle in {0,10,60,70}{\path (\angle:4) node[dot];}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

除了\pic命令之外,您还可以使用\draw命令 --获取彩色角度-- 或者fill=white也可以使用命令--两者都如下所示

在此处输入图片描述

    \draw pic[ draw,->,red, "$\theta_1$"{shift=(80:0.35),inner sep=1pt, 
    circle, draw},angle eccentricity=1.1, angle radius = 17mm] {angle = L1--O--L2}; 
    \pic[ draw,->,blue, "$\theta_2$"{fill=white},inner sep=1pt, circle,  draw,angle 
    eccentricity=1.1, angle radius = 10mm] {angle = x--O--L}; 

相关内容