Preamble
I use a lot of environments provided by tikz-timing
and pgfplots
packages.
Often i specify dimensions for some elements in tikz
picture.
For example, time delay between rises of two pulses at tikztimingtable
environment.
So i thought that one can define i macro which can draw in tikz
environment a parameterized dimension line with label, optional projection lines and custom arrows.
I have no idea how this could be implemented.
And i hope someone help me to implement my macro.
Main matter
Macro should be used in tikz
environment to draw dimension line defined by three points:
- two points of nodes between which dimension should be shown;
- one point of node on a guide along which dimension line should be drawn.
Marco usage should be:
\hdimline[7.2pt]{A}{B}{G}{d>.|<}{Label}
Where:
- A is
tikz
coordinates of node named "A", - B is for node "B",
- G is for node "G" which is on guide,
- "d>.|<" is design token,
- Label is label box contents,
- optional parameter is size of custom arrows.
Design token description
The design token should be similar to graphics of dimension line. Special characters are:
- "|" or "." mean to draw or not to draw projection line respectively; for example, ".|" is for right projection line only and "||" is for both;
- ">" and "<" mean to draw right-pointing arrow and left-pointing arrow respectively;
- "d" is for label placement.
I try to illustrate my idea with examples (see the applied code and picture).
The code
\documentclass[14pt,oneside]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english]{babel}
\usepackage{color}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
% Default arrow segment length is 7.2pt
\newlength{\dimarrowr}
\setlength{\dimarrowr}{7.2pt}
\begin{figure}[ht!]
\centering
\begin{tikzpicture}[line cap=round,line join=round]
% The picture with two given points
\fill[gray] (-2,-2) coordinate(A)
-- (2,2) coordinate(B)
coordinate[midway](C)
-- (2,-2)
-- cycle;
% The points that define each guide
% on which dimension line should be drawn
\coordinate (G1) at (0,4);
\coordinate (G2) at (0,3);
% Point marks
\fill (A) circle[radius=2pt];
\fill (B) circle[radius=2pt];
\fill (C) circle[radius=2pt];
% Horizontal dimension;
% should be used as \hdimline{A}{B}{G1}{|<d>|}[7.2pt]
% left projection line specified by left "|"
\draw (A) -- (A |- G1) -- ++(0,{\dimarrowr/3});
% right projection line specified by right "|"
\draw (B) -- (B |- G1) -- ++(0,{\dimarrowr/3});
% left pointing arrow specified by "<"
\draw (A |- G1) ++(10:{\dimarrowr})
-- ++(190:{\dimarrowr})
-- ++(-10:{\dimarrowr}) coordinate (lparrow_right_point);
% right pointing arrow specified by ">"
\draw (B |- G1) ++(170:{\dimarrowr})
-- ++(-10:{\dimarrowr})
-- ++(190:{\dimarrowr}) coordinate (rparrow_left_point);
% dimension line with label
\draw (A |- G1) -- (lparrow_right_point |- G1)
-- (rparrow_left_point |- G1)
node[midway,above,black] {$l_\text{H1}$}
-- (B |- G1);
% Horizontal dimension;
% should be used as \hdimline{A}{B}{G1}{.<d>|}[7.2pt]
% left projection line eliminated by left "."
% right projection line specified by right "|"
\draw (C) -- (C |- G2) -- ++(0,{\dimarrowr/3});
% left pointing arrow specified by "<"
\draw (A |- G2) ++(10:{\dimarrowr})
-- ++(190:{\dimarrowr})
-- ++(-10:{\dimarrowr}) coordinate (lparrow_right_point);
% right pointing arrow specified by ">"
\draw (C |- G2) ++(170:{\dimarrowr})
-- ++(-10:{\dimarrowr})
-- ++(190:{\dimarrowr}) coordinate (rparrow_left_point);
% dimension line with label
\draw (A |- G2) -- (lparrow_right_point |- G2)
-- (rparrow_left_point |- G2)
node[midway,above,black] {$l_\text{H2}$}
-- (C |- G2);
\end{tikzpicture}
\caption{Triangle with dimensions (labels inside)}
\end{figure}
\begin{figure}[ht!]
\centering
\begin{tikzpicture}[line cap=round,line join=round]
% The picture with two given points
\fill[gray] (-0.5,-0.5) coordinate(A)
-- (0.5,0.5) coordinate(B)
coordinate[midway](C)
-- (0.5,-0.5)
-- cycle;
% The points that define each guide
% on which dimension line should be drawn
\coordinate (G1) at (0,-1.5);
\coordinate (G2) at (0,-1);
% Point marks
\fill (A) circle[radius=2pt];
\fill (B) circle[radius=2pt];
\fill (C) circle[radius=2pt];
% Horizontal dimension;
% should be used as \hdimline{A}{B}{G1}{|<>|d}[7.2pt]
% left projection line specified by left "|";
\draw (A) -- (A |- G1) -- ++(0,-{\dimarrowr/3});
% right projection line specified by right "|"
\draw (B) -- (B |- G1) -- ++(0,-{\dimarrowr/3});
% left pointing arrow specified by "<"
\draw (A |- G1) ++(10:{\dimarrowr})
-- ++(190:{\dimarrowr})
-- ++(-10:{\dimarrowr}) coordinate (lparrow_right_point);
% right pointing arrow specified by ">"
\draw (B |- G1) ++(170:{\dimarrowr})
-- ++(-10:{\dimarrowr})
-- ++(190:{\dimarrowr}) coordinate (rparrow_left_point);
% dimension line with label;
% currently segment length is 4ex,
% but should be longer than contents by 1ex
\draw (A |- G1) -- (B |- G1)
-- ++(4ex,0)
node[midway,above,black] {$l_\text{H1}$};
% Horizontal dimension;
% should be used as \hdimline{A}{B}{G1}{d>.|<}[7.2pt]
% left projection line eliminated by left "."
% right projection line specified by right "|"
\draw (C) -- (C |- G2) -- ++(0,-{\dimarrowr/3});
% right pointing arrow specified by ">"
\draw (A |- G2) ++(170:{\dimarrowr})
-- ++(-10:{\dimarrowr})
-- ++(190:{\dimarrowr}) coordinate (rparrow_left_point);
% left pointing arrow specified by "<"
\draw (C |- G2) ++(10:{\dimarrowr})
-- ++(190:{\dimarrowr})
-- ++(-10:{\dimarrowr}) coordinate (lparrow_right_point);
% dimension line with label
\draw (rparrow_left_point |- G2)
++(-4ex,0)
-- (rparrow_left_point |- G2)
node[midway,above,black] {$l_\text{H2}$}
-- (lparrow_right_point |- G2)
-- ++({\dimarrowr/2},0);
\end{tikzpicture}
\caption{Triangle with dimensions (labels outside)}
\end{figure}
\end{document}
PS: Grammar check is welcome.
tikz-dimline
is interesting package, but it won't solve my problem.tikz-dimline
provide no variant with outside labels (see fig. 2 in my question). Moreover original arrowheads provided by package have incorrect graphics to me (the head of arrow should tap projection line). Maybe i should break my question in a few simple questions.tikz-dimline
.