How can I produce a dash-dotted line .-.-.-.-? I tried to find something in the tikz manual, but didn't find anything.


3 Answers 3


The various pre-defined dash patterns are documented in section 15.3.2 Graphic Parameters: Dash Pattern of the manual (for version 3.0.1.a dated 29 August 2015). They are dotted, dashed, dash dot and dash dot dot. Each of these have denser and looser variants, e.g. densely dashed and loosely dotted. Equivalently for the others.

In addition you can specify a custom pattern using e.g. dash pattern={on 4pt off 1pt on 2pt off 3pt}, which I guess is self explanatory.


\draw [thick,dash dot] (0,1) -- (5,1);
\draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (0,0) -- (5,0);


enter image description here


If you want to put a line like this in the text, and aligned better to the surrounding text, then you can add the baseline=<length> option to the tikzpicture. By default the bottom end of the tikzpicture is placed on the baseline of the surrounding text. If you add baseline=10pt then the tikzpicture will be placed so that y=10pt in its internal coordinate system is on the baseline of the surrounding text.

Here is an example. \tikz is a short form of the tikzpicture environment, intended for simple pictures placed in the text.


Lorem ipsum \tikz\draw [thick,dash dot] (0,0) -- (3,0); dolor sit amet

Lorem ipsum \tikz[baseline=-0.5ex]\draw [thick,dash dot] (0,0) -- (3,0); dolor sit amet

enter image description here

  • (x1, y1) and (x2, y2) seem to be coordinates. Is it right, that the coordinate with the lower x part is set to be wherever the environment ends? My tests tell so. Than how can I set the line in the middle line high, like appearing like this: before --- after
    – user1
    Commented Sep 4, 2016 at 20:21
  • *wherever the environment starts
    – user1
    Commented Sep 4, 2016 at 20:27
  • 1
    @Ben I'm not entirely sure what you mean, but I think you're after the baseline key, see the addition to my answer. Commented Sep 4, 2016 at 20:32
  • I am sorry, but how can it be written if the length is needed to be a fraction of textwidth or 2cm for example?
    – Diaa
    Commented Sep 4, 2016 at 20:40
  • 2
    @DiaaAbidou As mentioned above, the default unit vectors are 1cm, so a line from (0,0) to (2,0) would be 2cm. That said, you can also use explicit units, so \draw (0,0) -- (2cm,0); works. And TeX lengths work as well, so you can say e.g. \draw (0,0) -- (0.1\linewidth,0); Commented Sep 4, 2016 at 20:52

Here is a version using leaders. While all the parameters can be changed, the main ones are \dashdotline{<length>} to draw the line, with these configurations: \dashfrac{<percent of repetition used by dash>}; \replength=<repetition-length>\relax.

\newcommand\repfrac{.40}% PERCENT OF REPETITION USED BY DASH
\newcommand\dashfrac[1]{\renewcommand\repfrac{#1}}% MACRO TO ALTER \repfrac
\setlength\replength{8.5pt}% REPITITION LENGTH
\newcommand\rulewidth{.6pt}% DASH WIDTH
\newcommand\tdashfill[1][\repfrac]{\cleaders\hbox to \replength{%
\replength 17.5pt

enter image description here


Yet another solution with leaders, not perfect but as simple as possible:

\xleaders\hbox to 1em{$- \cdot$}\hfill $-$

If you will use this often, define some macro as \dashdotted, If you want a specific length instead of filling the line, simply enclose it in a \makebox (e.g.,\makebox[2cm]{\dashdotted}). MWE:


\def\dashdotted{\xleaders\hbox to 1em{$- \cdot$}\hfill $-$}
x\dashdotted 1\par 
xxxxx\dashdotted 1\par 
xxxxxxxxxx\dashdotted 1\par 
xxxxxxxxxxxxxxx\dashdotted 1

You must log in to answer this question.

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