我有以下一段代码,我想添加两点:
为红点(即线段的交点)添加标签。不幸的是,仅使用 ${...}$ 似乎不起作用。
我想从向量 a 画一个箭头到线段,表示该向量与其正交。
谢谢
\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);
\fill[red] (a) circle (1pt);
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3) node[midway,above=0.1cm] {$a$};
\end{tikzpicture}
\end{document}
答案1
您可以使用
\node
和它的label
键。您可以使用该
angles
库及其angle
图片。
结果:
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);
\fill[red] (a) circle (1pt);
\node[label=below:$r$] at (a) {};
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3)
node[midway,above=0.1cm] {$a$};
\coordinate (aux) at ([shift={(\angle+90:20pt)}]a_2);
\draw[<->,>=latex,red] pic[draw=red,angle radius=8pt]{angle = aux--a_2--a};
\end{tikzpicture}
\end{document}
使用引号库来为角度赋值:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);
\fill[red] (a) circle (1pt);
\node[label=below:$r$] at (a) {};
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3)
node[midway,above=0.1cm] {$a$};
\coordinate (aux) at ([shift={(\angle+90:20pt)}]a_2);
\draw[<->,>=latex,red] pic["{\tiny$90$}",draw=red,angle radius=8pt]{angle = aux--a_2--a};
\end{tikzpicture}
\end{document}
箭头的放大图像: