我想问一下如何在 LaTeX 中表示线段长度。下面是我绘制三角形的示例代码。然后,我想用 $d_1$ 表示线段 OA 的长度,用 $d_2$ 表示线段 OB 的长度。除了在线段下方添加文本外,我还希望显示分隔两个长度的尺寸线。有人能告诉我怎么做吗?
先感谢您。
\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\pgfmathsetmacro{\rvec}{0.9}
\begin{tikzpicture}
\usetikzlibrary{angles, quotes}[every edge quotes/.append style = {anchor=south, sloped}]
\fill (0,0) circle (2pt);
\draw[->] (0,0) node[below left] (O) {O} -- (8+2.2361,0);
\draw[->] (0,0) to (8,2) node[above] (P) {P};
\draw[->] (8,2) -- (8-2.2361,0) node[below left] (A) {A};
\draw[->] (8,2) to (8+2.2361,0) node[below right] (B) {B};
\end{tikzpicture}
\end{document}
答案1
我不知道您所说的“曲线”到底是什么意思。-但您可以使用包dimline
中的tikz-dimline
。像这样:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-dimline}
\begin{document}
\begin{tikzpicture}
\fill (0,0) circle (2pt);
\draw[->] (0,0) node[anchor=north east] (O) {O} -- (12,0) node[anchor=north] (los) {$\hat{l}$};
\draw[->] (0,0) --node[above] {$\vec{d}$} ++ (8,2) node[anchor=south west] (P) {P};
% How can I add an angle symbol at O.
% Is there an intelligent way of identifying these intersection points?
\draw[->] (8,2) -- (8-2.2361,0) node[anchor=north east] (A) {A};
\draw[->] (8,2) -- (8+2.2361,0) node[anchor=north west] (B) {B};
% How can I add curves to indicate the lengths?
\draw (0,0) -- ++ (8-2.2361,0);
\dimline{(8-2.2361,-1)}{(0,-1)} {$l_{min}$};
\draw (0,0) -- ++ (8+2.2361,0);
\dimline[extension start length=2 cm] {(8+2.2361,-2)}{(0,-2)} {$l_{max}$};
% The text l_max should be away from the line.
\draw[dashed] (8,0) -- (8,2);
\draw (8,0.25) -| (7.75,0);
\draw (8,2) circle (3);
\end{tikzpicture}
\end{document}