以下声明
\tikzset{
ncbar/.style={
to path={%
($(\tikztostart)!#1!90:(\tikztotarget)$)
-- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}},
ncbar/.default=0.5cm,
}
不接受\tikztonodes
命令,因为两个节点
\draw[<->] (A) to[ncbar=0.2](C) node[midway, sloped, above] {\small $30dm$};
\draw[<->] (C) to[ncbar=0.33](B) node[midway, sloped, above] {\small $40dm$};
未出现在图片中:
代码灵感来自
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgf,tikz,pgfplots, tikz-cd}
\usetikzlibrary{arrows, intersections,decorations.markings, patterns, calc}
\usepackage{tkz-euclide}
\usepackage{calc}
\tikzset{
ncbar/.style={
to path={%
($(\tikztostart)!#1!90:(\tikztotarget)$)
-- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}},
ncbar/.default=0.5cm,
}
\begin{document}
\begin{tikzpicture}[remember picture]
% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\coordinate[] (A) at (-1,0);
\coordinate[] (B) at (1,0);
\coordinate[] (C) at (-0.5,0.86602);
\draw (A) -- (B) -- (C) -- cycle;
\draw (B) arc[start angle=0, end angle=180, radius=1];
\begin{pgfinterruptboundingbox}
\clip (A) -- (B) -- (C) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
\fill[fill=green!20!white] (B) arc[start angle=0, end angle=180, radius=1];
\draw[<->] (A)+(0,-.2)--($(B)+(0,-.2)$) node[midway, below] {\small $50dm$};
\draw[<->] (A) to[ncbar=0.2](C) node[midway, sloped, above] {\small $30dm$};
\draw[<->] (C) to[ncbar=0.33](B) node[midway, sloped, above] {\small $40dm$};
\end{tikzpicture}
\end{document}
答案1
抱歉,我无法弄清楚您的代码的大部分内容。如果问题是重现显示的图像,那么执行此操作的 MWE 可以(简单得多):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc,
decorations.markings,
quotes}
\usepackage{siunitx}
\tikzset{
every edge/.style = {draw, Straight Barb-Straight Barb},
every edge quotes/.style = {auto, font=\footnotesize, sloped}
}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (-1,0);
\coordinate (B) at (1,0);
\coordinate (C) at (-0.5,0.86602);
%
\draw[fill=green] (B) arc (0:180:1);
\draw[fill=white] (A) -- (B) -- (C) -- cycle;
%
\draw
([yshift=-2mm] A)
edge["\qty{50}{\deci\metre}" below]
([yshift=-2mm] B)
($(B)!7mm!-90:(C)$)
edge["\qty{40}{\deci\metre}"]
($(C)!7mm!+90:(B)$)
($(A)!3mm!90:(C)$)
edge["\qty{30}{\deci\metre}"]
($(C)!3mm!-90:(A)$)
;
\end{tikzpicture}
\end{document}
附录:
你的代码有什么问题?
- 它没有必要那么复杂,所以很容易迷失其中
- 带标签的箭头代码是错误的。而不是使用
\draw[<->] (A) to[ncbar=0.2](C) node[midway, sloped, above] {\small $30dm$};
\draw[<->] (C) to[ncbar=0.33](B) node[midway, sloped, above] {\small $40dm$};
它应该是:
\draw[<->] (A)
to[ncbar=0.3] node[font=\small, sloped, above] {$30dm$}
(C);
\draw[<->] (C)
to[ncbar=0.4] node[font=\small, sloped, above] {$30dm$}
(B);
- 清理您的文档示例后,您的文档示例可以是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,
calc,
decorations.markings,
intersections,
}
\usepackage{tkz-euclide}
\usepackage{calc}
\tikzset{
ncbar/.style={
to path={%
($(\tikztostart)!#1!90:(\tikztotarget)$)
-- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}},
ncbar/.default=0.5cm,
}
\begin{document}
\begin{tikzpicture}
\coordinate[] (A) at (-1,0);
\coordinate[] (B) at (1,0);
\coordinate[] (C) at (-0.5,0.86602);
\draw[fill=green!20!white]
(B) arc[start angle=0, end angle=180, radius=1];
\draw[fill=white]
(A) -- (B) -- (C) -- cycle;
%
\draw[<->] ($(A)+(0,-.2)$) --
node[font=\small, below] {$50dm$}
($(B)+(0,-.2)$);
\draw[<->] (A)
to[ncbar=0.3] node[font=\small, sloped, above] {$30dm$}
(C);
\draw[<->] (C)
to[ncbar=0.4] node[font=\small, sloped, above] {$30dm$}
(B);
\end{tikzpicture}
\end{document}
并给出以下结果:
但是,如果考虑建议的更改,您的代码也可以获得相同的结果。使用它,您至少需要两次编译才能获得正确的结果。
通过与 MWE(最小工作示例)进行比较,可以清楚地看到,文档示例中的大部分代码都是不必要的,因此可以视为杂乱,应予以省略。
答案2
另一个解决方案是使用 TikZ,您可以使用even odd rule
更简洁的代码。
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\r{5/2}
\pgfmathsetmacro{\t}{atan(3/4)}
\path
(-\r,0) coordinate (A)
(\r,0) coordinate (B)
({180-2*\t}:\r) coordinate (C)
;
\tikzset{n/.style={midway,sloped,fill=white,text=black}}
\draw[|<->|,gray] ($(B)!13mm!-90:(C)$)--($(C)!13mm!90:(B)$)
node[n]{$40\,\mathrm{dm}$};
\draw[|<->|,gray] ($(A)!9mm!90:(C)$)--($(C)!9mm!-90:(A)$)
node[n]{$30\,\mathrm{dm}$};
\draw[|<->|,gray] ([yshift=-5mm]A)--([yshift=-5mm]B)
node[n]{$50\,\mathrm{dm}$};
\draw[fill=green,even odd rule]
(B) arc(0:180:\r)--cycle
(A)--(B)--(C)--cycle;
\end{tikzpicture}
\end{document}
尝试使用 Asymptote。似乎siunitx
不适用于http://asymptote.ualberta.ca/
//usepackage("siunitx"); // It seems does not work on http://asymptote.ualberta.ca/
unitsize(1cm);
real r=5/2;
real t=aTan(3/4); // in degrees
pair A=(-r,0), B=(r,0), C=r*dir(180-2t);
path tri=A--B--C--cycle;
path cir=arc((0,0),r,0,180)--cycle;
transform s=shift(0,-.4);
draw(Label("$50 \,\mathrm{dm}$",black,Fill(white),align=(0,0)),s*A--s*B,gray,Arrows(TeXHead),Bars);
pair Bt=B+1.3*unit(rotate(-90,B)*(C-B)); //dot(Bt);
pair Ct=C+1.3*unit(rotate(90,C)*(B-C)); //dot(Ct);
draw(Label("$40 \,\mathrm{dm}$",black,Rotate(Bt-Ct),Fill(white),align=(0,0)),Bt--Ct,gray,Arrows(TeXHead),Bars);
pair As=A+.9*unit(rotate(90,A)*(C-A)); //dot(Bt);
pair Cs=C+.9*unit(rotate(-90,C)*(A-C)); //dot(Ct);
draw(Label("$30 \,\mathrm{dm}$",black,Rotate(Cs-As),Fill(white),align=(0,0)),Cs--As,gray,Arrows(TeXHead),Bars);
filldraw(tri^^cir,evenodd+yellow);
shipout(bbox(5mm,invisible));