在 Tikz 中以箭頭標記頂點

在 Tikz 中以箭頭標記頂點

我知道這個問題已經在這裡被問了很多時間,但我已經看過很多答案,但由於某種原因我仍然無法讓它發揮作用。下面是我的程式碼和輸出:

\documentclass[a4paper, 11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc,angles,quotes,positioning}

\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
% making the diagram
\draw (0,0) node (O) [black, below]{$O$}
-- (-2,2.5) node (C) [black, left]{$C$}
-- (3,4) node (D) [black, right] {$D$}
-- cycle;
\draw (-2,2.5)
-- (-2,4.5) node (B) [black,left] {$B$}
-- (3,6) node (A) [black, right] {$A$}
-- (3,4);
\draw (0,0)
-- (-2,4.5);
\draw (0,0)
-- (3,6);
% putting equal marks on sides AB and CD
\draw[decoration = {markings,mark=at position 0.5 with 
  {\draw(0,-5pt)--(0,5pt);}},postaction={decorate}] (-2,2.5)--(3,4);
  \draw[decoration = {markings,mark=at position 0.5 with 
  {\draw(0,-5pt)--(0,5pt);}},postaction={decorate}] (-2,4.5)--(3,6);
% (trying) to label vertex COD
pic["$60^\circ$",draw=black,<->,angle eccentricity=1.2,angle radius=1cm] {angle=C--O--D};
\end{tikzpicture}
\end{figure}
\end{document}

在此輸入影像描述

我想要的輸出如下:

在此輸入影像描述

附錄

看看給定的答案,我現在可以標記角度 COD,但是當我使用完全相同的方法來標記 AOD 和 BOC 時,令人憤怒的是它似乎不起作用。

pic["$15^\circ$",draw=black,->,angle eccentricity=1.2,angle radius=1cm] {angle=B--O--C};
pic["$25^\circ$",draw=black,->,angle eccentricity=1,angle radius=1cm] {angle=A--O--D};

在此輸入影像描述

謝謝你的幫忙!

答案1

完整編輯:您的程式碼的問題在於您使用的是擴展物件的節點,而不是座標。一旦改變,你的pic工作就會很好。

\documentclass[a4paper, 11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,backgrounds}
\usetikzlibrary{calc,angles,quotes,positioning}
\newcommand{\DrawArcAngle}[6][]{% just for emergencies
\pgfmathanglebetweenpoints{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#2}{center}}
\xdef\angleA{\pgfmathresult}
\pgfmathanglebetweenpoints{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}
\xdef\angleB{\pgfmathresult}
\draw[#1] ($(#3)+(\angleA:#5)$) arc [start angle=\angleA,end angle=\angleB,radius=#5]
#6;
}
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
% making the diagram
\coordinate[label=below:$O$] (O) at (0,0);
\coordinate[label=left:$C$] (C) at (-2,2.5);
\coordinate[label=right:$D$] (D) at (3,4);
\coordinate[label=left:$B$] (B) at (-2,4.5);
\coordinate[label=right:$A$] (A) at (3,6);
\draw (O) -- (C) -- (D)-- cycle;
\draw (C) -- (B) -- (A)-- (D);
\draw (O)-- (B);
\draw (O) -- (A);
% putting equal marks on sides AB and CD
\draw[decoration = {markings,mark=at position 0.5 with 
  {\draw(0,-5pt)--(0,5pt);}},postaction={decorate}] (C)--(D);
  \draw[decoration = {markings,mark=at position 0.5 with 
  {\draw(0,-5pt)--(0,5pt);}},postaction={decorate}] (B)--(A);
%\DrawArcAngle[->,draw]{C}{O}{D}{1cm}{node[midway,above]{$60^\circ$}}
\draw (D)--(O)--(C)
pic["$60^\circ$",draw=black,<->,angle eccentricity=1.2,angle radius=1cm] {angle=D--O--C};
\draw (B)--(O)--(C)
pic["$15^\circ$",draw=black,<->,angle eccentricity=1.2,angle radius=1.8cm] {angle=B--O--C};
\draw (D)--(O)--(A)
pic["$25^\circ$",draw=black,<->,angle eccentricity=1.2,angle radius=2.4cm] {angle=D--O--A};
\end{tikzpicture}
\end{figure}
\end{document}

在此輸入影像描述

相關內容