1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
%% Dimension line for LaTeX/TikZ
%% Copyright © 2013 Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
%%
%% This file may be distributed and/or modified
%%
%% 1. under the LaTeX Project Public License and/or
%% 2. under the WTF Public License.
%%
%%
%% This simplify the creation drawing of dimension arrows.
%%
%%
%% To install it copy the tango directory to either:
%% - $TEXHOME/tex/latex/
%% - ~/texmf/tex/latex/
%% - ~/Library/texmf/tex/latex
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tikz-dimline}[2013/03/13 v1.0 initial version]
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\RequirePackage{ifthen}
\usetikzlibrary{calc,decorations.markings,arrows}
\makeatletter
\pgfkeys {
/dimline/.cd,
execute style/.style = {#1},
execute macro/.style = {/dimline/execute style/.expand once=#1},
}
\newdimen\dimline@arrow@linewidth
\pgfarrowsdeclare{dimline}{dimline}
{
\arrowsize=1\pgflinewidth
\pgfarrowsleftextend{0\arrowsize}
\pgfarrowsrightextend{5\arrowsize}
} {
\arrowsize=1\pgflinewidth
\pgfsetdash{}{0pt} % do not dash
% |
\pgfsetlinewidth{.5\arrowsize}
\pgfpathmoveto{\pgfpoint{4.75\arrowsize}{3\arrowsize}}
\pgfpathlineto{\pgfpoint{4.75\arrowsize}{-3\arrowsize}}
\pgfusepathqstroke
% >
\pgfsetlinewidth{0.01pt}
\pgfpathmoveto{\pgfpoint{4.5\arrowsize}{0pt}}
\pgfpathlineto{\pgfpoint{-3\arrowsize}{2\arrowsize}}
\pgfpathlineto{\pgfpoint{-3\arrowsize}{-2\arrowsize}}
\pgfpathclose
\pgfusepathqfillstroke
}
\pgfarrowsdeclare{dimline reverse}{dimline reverse}
{
\arrowsize=1\pgflinewidth
\pgfarrowsleftextend{-5\arrowsize}
\pgfarrowsrightextend{0\arrowsize}
} {
\arrowsize=1\pgflinewidth
\pgfsetdash{}{0pt} % do not dash
% |
\pgfsetlinewidth{0.5\arrowsize}
\pgfpathmoveto{\pgfpoint{-0.25\arrowsize}{3\arrowsize}}
\pgfpathlineto{\pgfpoint{-0.25\arrowsize}{-3\arrowsize}}
\pgfusepathqstroke
% >
\pgfsetlinewidth{0.01pt}
\pgfpathmoveto{\pgfpoint{0pt}{0pt}}
\pgfpathlineto{\pgfpoint{7.5\arrowsize}{2\arrowsize}}
\pgfpathlineto{\pgfpoint{7.5\arrowsize}{-2\arrowsize}}
\pgfpathclose
\pgfusepathqfillstroke
}
% measure lenght
% http://tex.stackexchange.com/questions/123913
\newcommand{\dimline@do@nothing}[1]{#1}%
% http://tex.stackexchange.com/questions/58283/tikz-how-to-determine-the-vector-between-two-co-ordinates
% #1: optional keys parameters
% #2: start point
% #3: end point
% #4: text
\newcommand{\dimline}[4][]{%
\pgfplotsifinaxis{%
\let\dimline@internal\pgfplotsextra%
}{%
\let\dimline@internal\dimline@do@nothing%
}%
\dimline@internal{
\pgfkeys{
dimline/.is family,
dimline,
color/.initial = black,
extension start length/.initial=1cm,
extension end length/.initial=1cm,
extension start angle/.initial=-90,
extension end angle/.initial=90,
line style/.initial = {},
label style/.initial = {},
extension style/.initial = {},
extension start style/.initial = {},
extension start path/.initial = {},
extension end style/.initial = {},
extension end path/.initial = {},
#1,
line style/.get = \dimline@line@style,
label style/.get = \dimline@label@style,
extension style/.get = \dimline@extension@style,
extension start style/.get = \dimline@extension@start@style,
extension start path/.get = \dimline@extension@start@path,
extension end style/.get = \dimline@extension@end@style,
extension end path/.get = \dimline@extension@end@path,
}
\begin{scope} [
line/.style = {
color=\pgfkeysvalueof{/dimline/color},
arrows=dimline-dimline,
/dimline/execute macro = \dimline@line@style,
},
extension/.style = {
color=\pgfkeysvalueof{/dimline/color}!40, line width=0.01,
/dimline/execute macro = \dimline@extension@style,
},
extension start/.style = {
extension,
/dimline/execute macro = \dimline@extension@start@style
},
extension end/.style = {
extension,
/dimline/execute macro = \dimline@extension@end@style,
},
label/.style = {
fill=white, align=center, sloped=true, pos=0.5,
/dimline/execute macro = \dimline@label@style
},
]
\coordinate (a) at #2 {};
\coordinate (b) at #3 {};
\ifthenelse{\equal{\dimline@extension@start@path}{}}{
\coordinate (a to b) at ($(a)!\pgfkeysvalueof{/dimline/extension start length}!\pgfkeysvalueof{/dimline/extension start angle}:(b)$);
\draw [extension start] (a.center) -- (a to b);
} {
\draw [extension start] plot coordinates {\dimline@extension@start@path};
}
\ifthenelse{\equal{\dimline@extension@end@path}{}}{
\coordinate (b to a) at ($(b)!\pgfkeysvalueof{/dimline/extension end length}!\pgfkeysvalueof{/dimline/extension end angle}:(a)$);
\draw [extension end] (b.center) -- (b to a);
} {
\draw [extension end] plot coordinates {\dimline@extension@end@path};
}
\draw[line] (a.center) -- (b.center) node[label] {#4};
\end{scope}
}
}
\@ifclassloaded{beamer}{%
\renewcommand<>{\dimline}[4][]{\only#5{\beameroriginal{\dimline}[#1]{#2}{#3}{#4}}}
}
\makeatother
\endinput
%% tikz-dimline.sty ends here.
|