108

Is there a way to get values for predefined dash patterns such as dotted? I would like to use those in another program to create the same visual experience. Or do I have to define my own patterns in order to have the same values?

1 Answer 1

173
+450

You can find the definitions of these and many others in the tikz.code.tex file in your distribution (e.g. MikTeX has it under C:\Program Files (x86)\MiKTeX 2.9\tex\generic\pgf\frontendlayer\tikz\ )

\tikzstyle{solid}=                   [dash pattern=]
\tikzstyle{dotted}=                  [dash pattern=on \pgflinewidth off 2pt]
\tikzstyle{densely dotted}=          [dash pattern=on \pgflinewidth off 1pt]
\tikzstyle{loosely dotted}=          [dash pattern=on \pgflinewidth off 4pt]
\tikzstyle{dashed}=                  [dash pattern=on 3pt off 3pt]
\tikzstyle{densely dashed}=          [dash pattern=on 3pt off 2pt]
\tikzstyle{loosely dashed}=          [dash pattern=on 3pt off 6pt]
\tikzstyle{dashdotted}=              [dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt]
\tikzstyle{densely dashdotted}=      [dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt]
\tikzstyle{loosely dashdotted}=      [dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt]

For quick comparison, see the output below:

enter image description here

7
  • 12
    Damn, you beat me to it by about 15 seconds! This is better than my one too, so +1!
    – qubyte
    Commented Feb 21, 2012 at 12:58
  • 1
    side question: why is the line width referenced using \the in the dashdotted variants, but not in the dotted variants?
    – burnpanck
    Commented Jul 31, 2015 at 14:20
  • 1
    @burnpanck Works both ways so probably just inconsistency.
    – percusse
    Commented Jul 31, 2015 at 16:10
  • PGF employs the full math parser for dash pattern. You can even do dash pattern=on2off3*3on5, which means dash pattern=on 2pt off 9pt on 5pt off 2pt on 9pt off 5pt.
    – Symbol 1
    Commented Nov 15, 2019 at 22:46
  • 1
    @Felipe, You need to add some code \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.11} \begin{document} begin{tikzpicture} \begin{axis}[ axis lines = left, xmin=-2, xmax=3, ymin=-2, ymax=3, after end axis/.code={ \draw[dashed,blue,->] (axis cs:1,1) -- (axis cs:2,0); } ] \end{axis} \end{tikzpicture} \end{document}
    – Kapil
    Commented Jun 1, 2020 at 0:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .