2

Is there a way to personalize the lines constructed with dim? Make them dotted and red, for instance?

\documentclass[tikz,border=2cm]{standalone}

\usepackage{tkz-euclide}

\begin{document}

    \begin{tikzpicture}
        \tkzDefPoints{0/3/A, 0/-3/B}
        \tkzDrawPoints(A,B) 
        \tkzDrawSegment[dim={\(l\),2cm,right=2mm}](A,B)
        \tkzLabelPoints[left](A,B)
    \end{tikzpicture}
\end{document}

enter image description here

3

Here is an easy way with plain TikZ. In case you need a lot of such dimline, then simly make a new command.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\path 
(0,3)  coordinate (A) node[left]{$A$}
(0,-3) coordinate (B) node[left]{$B$};
\draw[red,dotted] (A)--+(0:2.5) (B)--+(0:2.5);
\draw[red,<->] ([shift={(0:2)}]A)--([shift={(0:2)}]B) node[midway,right]{$l$};
\draw[thick,blue] (A)--(B);
\fill[blue] (A) circle(1.5pt) (B) circle(1.5pt);
\end{tikzpicture}
\end{document}
| improve this answer | |
2

It seems the style of \tkzDrawSegment[dim={...}] is hardcoded, and is written directly in pgf codes. Currently I am not capable of extending it and providing flexible user options, and below is my first try.

\documentclass[tikz,border=2cm]{standalone}

\usepackage{tkz-euclide}

\makeatletter
% originally defined in tkz-obj-eu-draw-lines.tex
\pgfdeclaredecoration{add dim}{final}{
\state{final}{% 
\pgfmathsetmacro{\dist}{\pgfkeysvalueof{/pgf/decoration/distance}}
          \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
          \pgfpathlineto{\pgfpoint{0pt}{1.2*\dist}}   
          \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}} 
          \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{1.2*\dist}}
          % start of patch
          \pgfusepath{stroke}  
          \pgfsetarrowsstart{latex}
          \pgfsetarrowsend{latex}
          \expandafter\pgfsetdash\tkz@dim@dashpattern
          \pgfsetstrokecolor{\tkz@dim@color}
          % end of patch
          \pgfpathmoveto{\pgfpoint{0pt}{\dist}}
          \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}} 
          \pgfusepath{stroke} 
          \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
          \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
}}

\tikzset{
  dim color/.store in=\tkz@dim@color,
  dim color/.initial=black,
  % similar to code for \tikzoption{dash pattern}{...}
  dim dash pattern/.code={%
    \def\tikz@temp{#1}%
    \ifx\tikz@temp\pgfutil@empty%
      \def\tkz@dim@dashpattern{{}{0pt}}%
    \else%
      \def\tikz@dashpattern{}%
      \expandafter\tikz@scandashon\pgfutil@gobble#1o\@nil%
      \edef\tkz@dim@dashpattern{{\tikz@dashpattern}{\noexpand\tikz@dashphase}}%
    \fi
  },
  dim dash pattern=,
}  
\makeatother

\begin{document}


    \begin{tikzpicture}
        \tkzDefPoints{0/3/A, 0/-3/B}
        \tkzDrawPoints(A,B) 
        \tkzDrawSegment[dim={\(l\),2cm,right=2mm}, dim color=red, dim dash pattern={on 2pt off 2pt}](A,B)
        \tkzLabelPoints[left](A,B)
    \end{tikzpicture}
\end{document}

enter image description here

I've opened a feature request here: https://github.com/tkz-sty/tkz-euclide/issues/5.

| improve this answer | |
  • 1
    Alain Matthes (tkz-euclide maintainer) gave the code to have dotted lines here : Draw dimension of a line as a decoration in TikZ – AndréC Jul 14 at 6:37
  • @AndréC That answer hardcoded \pgfsetdash{{0.1cm}{0.1cm}{0.1cm}{0.1cm}}{0cm}, which is even less flexible than mine. – muzimuzhi Z Jul 14 at 12:53
  • All right, let's hope that Alain Matthes will include your code in his package. – AndréC Jul 14 at 16:50

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.