Draw a dash-dotted line
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.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [thick,dash dot] (0,1) -- (5,1);
\draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (0,0) -- (5,0);
\end{tikzpicture}
\end{document}
Addendum
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.
\documentclass{article}
\usepackage{tikz}
\begin{document}
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
\end{document}
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
.
\documentclass[10pt]{article}
\newlength\replength
\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
\def\dashht{.5\dimexpr\ht\strutbox-\dp\strutbox\relax}
\newcommand\tdashfill[1][\repfrac]{\cleaders\hbox to \replength{%
\smash{\rule[\dashht]{\repfrac\replength}{\rulewidth}%
\kern.5\dimexpr\replength-\repfrac\replength-2.5pt\relax%
\raisebox{\dimexpr\dashht-.3pt}{.}}}\hfill}
\newcommand\dashdotline[1]{%
\makebox[#1][l]{\tdashfill\hfil}}
\begin{document}
x\dashdotline{2in}y\par
\replength 17.5pt
x\dashdotline{1in}y\par
\dashfrac{.66}
x\dashdotline{1in}y
\end{document}
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:
\documentclass[a5paper,twocolumn]{article}
\def\dashdotted{\xleaders\hbox to 1em{$- \cdot$}\hfill $-$}
\begin{document}
x\dashdotted 1\par
x\makebox[2cm]{\dashdotted}1\par
xxxxx\dashdotted 1\par
xxxxxxxxxx\dashdotted 1\par
xxxxxxxxxxxxxxx\dashdotted 1
\end{document}