我正在尝试注释用 tikz 制作的技术图纸。继塔拉斯,我需要能够像下面所示的那样在侧面进行注释,因为我的注释文本可能比注释之间的距离更长(我知道在测试示例中情况并非如此):
我想出了这个解决方案,它适用于水平和垂直边界情况:
% right hand side horizontal [node1 is left of node2]
\Cote[2 cm]{(node1)}{(node2)}{\phantom{$L_\text{test}$}}<h>[Cote node/.append style={pos=1, anchor=west, name=dummypos}];
\draw (node2|-dummypos) -- (dummypos.east);
\node at (dummypos)[above]{$L_\text{test}$};
% left hand side horizontal
\Cote[2 cm]{(node1)}{(node2)}{\phantom{$L_\text{test}$}}<h>[Cote node/.append style={pos=0,anchor=east,name=dummypos}];
\draw (node2|-dummypos) -- (dummypos.west);
\node at (dummypos)[above]{$L_\text{test}$};
% above vertical [node2 is above node3]
\Cote[2cm]{(node2)}{(node3)}{\phantom{$L_\text{test}$}}<v>[Cote node/.append style={pos=1,anchor=west,name=dummypos,rotate=90}];
\draw (node3-|dummypos) -- (dummypos.east);
\node at (dummypos)[above,rotate=90]{$L_\text{test}$};
% below vertical:
\Cote[2cm]{(node2)}{(node3)}{\phantom{$L_\text{test}$}}<v>[Cote node/.append style={pos=0,anchor=east,name=dummypos,rotate=90}];
\draw (node3-|dummypos) -- (dummypos.west);
\node at (dummypos)[above,rotate=90]{$L_\text{test}$};
我觉得这个方法效果很好,可以自动调整扩展栏的尺寸。但当然,多次写入这个方法很麻烦,所以我想可以将其集成到 \Cote 命令中,但在这里我失败了。
- 是否有人能够将其集成到
NewDocumentCommand
原始Cote
命令中(参见上面的链接)作为案例 h、v 的选项来指定是否想要在尺寸旁边进行注释(r、l、t、b - 右、左、上、下)? - 作为一个优点,可能对某些人有用,如果它也能覆盖斜置的情况就好了(我还没有解决这个问题,因为我现在不需要它)。
更新:
刚刚注意到,在这些情况下,我需要箭头从尺寸线的外部开始,因此请使用以下方法更新上述示例:
\Cote[2 cm]{(node1)}{(node2)}{\phantom{$L_\text{test}$}}<h>[Cote node/.append style={pos=1, anchor=west, name=dummypos, xshift=3pt}, Cote arrow/.append style={>-<, shorten >= -3pt,shorten <= -3pt}];
\draw (node2|-dummypos) -- (dummypos.east);
\node at (dummypos)[above]{$L_\text{test}$};
平均能量损失
%! TEX root = standard_socket.tex
\documentclass[tikz,border=3pt 0 0 0]{standalone}
% taken from https://tex.stackexchange.com/a/180110/97536
\usepackage{xparse}
\usetikzlibrary{calc}
\RequirePackage{pdftexcmds}
\makeatletter
\let\pdfstrcmp\pdf@strcmp
\let\pdffilemoddate\pdf@filemoddate
\tikzset{%
Cote node/.style={%
midway,
%sloped,
fill=white,
inner sep=1.5pt,
outer sep=2pt
},
Cote arrow/.style={%
<->,
>=latex,
very thin
}
}
\makeatletter
\NewDocumentCommand{\Cote}{%
s % cotation avec les fleches a lexterieur
D<>{1.5pt} % offset des traits
O{.75cm} % offset de cotation
m % premier point
m % second point
m % etiquette
D<>{o} % () coordonnées -> angle
% h -> horizontal,
% v -> vertical
% o or what ever -> oblique
O{} % parametre du tikzset
}{%
{\tikzset{#8}
\coordinate (@1) at #4 ;
\coordinate (@2) at #5 ;
\if #7H % Cotation traits horizontaux
\coordinate (@0) at ($($#4!.5!#5$) + (#3,0)$) ;
\coordinate (@5) at ($#5+(#3,0)$) ;
\coordinate (@4) at ($#4+(#3,0)$) ;
\else
\if #7V % Cotation traits verticaux
\coordinate (@0) at ($($#4!.5!#5$) + (#3,0)$) ;
\coordinate (@5) at ($#5+(0,#3)$) ;
\coordinate (@4) at ($#4+(0,#3)$) ;
\else
\if #7v % Cotation verticale
\coordinate (@0) at ($($#4!.5!#5$) + (#3,0)$) ;
\coordinate (@4) at (@0|-@1) ;
\coordinate (@5) at (@0|-@2) ;
\else
\if #7h % Cotation horizontale
\coordinate (@0) at ($($#4!.5!#5$) + (0,#3)$) ;
\coordinate (@4) at (@0-|@1) ;
\coordinate (@5) at (@0-|@2) ;
\else % cotation encoche
\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@
\coordinate (@5) at ($#7!#3!#5$) ;
\coordinate (@4) at ($#7!#3!#4$) ;
\else % cotation oblique
\coordinate (@5) at ($#5!#3!90:#4$) ;
\coordinate (@4) at ($#4!#3!-90:#5$) ;
\fi\fi\fi\fi\fi
\draw[very thin,shorten >= 2*#2,shorten <= -2*#2] (@4) -- #4 ;
\draw[very thin,shorten >= 2*#2,shorten <= -2*#2] (@5) -- #5 ;
\IfBooleanTF #1 {% avec etoile
\draw[Cote arrow,-] (@4) -- (@5)
node[Cote node] {#6\strut};
\draw[Cote arrow,<-] (@4) -- ($(@4)!-6pt!(@5)$) ;
\draw[Cote arrow,<-] (@5) -- ($(@5)!-6pt!(@4)$) ;
}{% sans etoile
\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@
\draw[Cote arrow] (@5) to[bend right]
node[Cote node] {#6\strut} (@4) ;
\else
\draw[Cote arrow] (@4) -- (@5)
node[Cote node] {#6\strut};
\fi
}}
}
\makeatother
\begin{document}
\begin{tikzpicture}[]
% coordinates
\coordinate(node1) at (0,0);
\coordinate(node2) at (1,0);
\draw[red](node1) -- (node2);
%Connotations
% horizontal
\Cote[1cm]{(node1)}{(node2)}{\phantom{Ltest}}<h>[Cote node/.append style={pos=1, anchor=west, name=Llinext, xshift=3pt}, Cote arrow/.append style={>-<, shorten >= -3pt,shorten <= -3pt}];
\draw[Cote arrow, -] (node2|-Llinext) -- (Llinext.east);
\node at (Llinext)[above]{Ltest};
\end{tikzpicture}
\end{document}