3

I always find my self doing a lot of repetition with fixed TikZ code blocks that I have to rewrite over and over again. My question is that, is it possible to create a block of TikZ executable commands (not just styles) inside a single argument and call that argument as a style?

Consider this:

\usepackage{tikz}
\usetikzlibrary{calc}
\begin{tikzpicture}
\coordinate [label = below:A](A) at (0, 0);
\coordinate [label = above:B](B) at (3, 3);
\draw (A) -- (B);
\draw [|-|, thin] ($(A)! 8mm !90:(B)$)  -- node [sloped, midway, fill = white]{$3$cm}
($(B)! -8mm !90:(A)$);%This is too long and It would awesome to abstract it
\end{tikzpicture}

enter image description here

What I would like to know is if there any thing like

\tikzset{
dimension line/.code arg={from#1to#2value#3}
    draw the dimension line between (A) and (B),
    add a node in the middle with blah style and blau value
}

So that using

\draw[dimension line=from A to B value 3cm] (A)--(B);

will yield the same output. That will help do the job with minimal effort and allow abstraction, I find this example simple enough in order to under stand how to create code blocks in TikZ. Thank you.

2

This is more a long comment than a real answer.

Although all tikz-dimline examples use cartesian coordinates, it's possible to use named ones:

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz-dimline}

\begin{document}
\begin{tikzpicture}

\draw[red] (0,0) coordinate (A) -- (45:3) coordinate (B);
\dimline[color=blue]{([shift={(-3mm,3mm)}]A)}{([shift={(-3mm,3mm)}]B)}{3cm};
\end{tikzpicture}
\end{document}

enter image description here

In any case, I've finally found the question I was looking for:

Draw dimension of a line as a decoration in TikZ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.