Is there a way to get a dotted line with prescribed density, for instance 10 dots per centimeter, instead of the default?

With Jesse's comment :


\tikzstyle{cm dotted}=[dash pattern=on \pgflinewidth off .85mm ]


\draw[cm dotted,line width=.15mm,step=.5] (0,0) grid (5,4) ;


Still an unwanted shift of half a linewidth. The horizontal and vertical crossing points are not on at the right place. I understand why, but I don't know how fix it.

  • 1
    Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. A suggestion: Do us a favour and change your username to something more telling than "user45209" (any nickname is good). – egreg Feb 1 '14 at 11:46
  • This could provide some directions -- tex.stackexchange.com/a/45276/34618 – Jesse Feb 1 '14 at 12:32
  • @Jesse, it goes in the good direction. It works but still a unwanted shift of half a linewith. – Tarass Feb 1 '14 at 13:14
  • You could update your question and give a more specific concerns, experts here are ready to help out. – Jesse Feb 1 '14 at 13:33
  • I did it and I put a try in the direction you've give. – Tarass Feb 1 '14 at 13:51

I think this does it. The size of the dot is determined by the line width. The trick is to use a dash of length 0. Which I suppose shouldn't work, but seems to.


  dots/.style args={#1per #2}{%
    line cap=round,
    dash pattern=on 0 off #2/#1


\foreach \i in {1,...,20}{
    \draw [help lines] grid (4,1);
    \draw [very thick, dots=\i per 1cm] 
      (0,.5) -- (4,.5) 
      node [at start, above right] {\i\ dot\ifnum\i>1s\fi\ per 1cm};


enter image description here

  • It works just fine, the grid is perfect. – Tarass Feb 1 '14 at 14:20
  • @MarkWibrow How do you make that animated image? (gif I assume). Is it easy to do? – Jonathan Komar Nov 17 '16 at 12:20
  • @macmadness86 open the PDF in gimp with pages as layers, reverse the layers (Layer->Stack->Reverse layer order) and then export to as a gif. It is also possible to optimise the animation (Filters>Animation->Optimise for GIF) – Mark Wibrow Nov 18 '16 at 14:03

With dotsep in PSTricks.


enter image description here



    \foreach \i in {2,...,10}{%
        \rput[t](3,1.75){\i\ dots per cm}   

enter image description here

  • With pstricks I usualy use psgrid and it works find. I know how to do this with metapost. But now I need a tikz command (without foreach), but a style to apply on a line or on a grid. – Tarass Feb 1 '14 at 12:50
  • @Tarass: OK. The multido in my answer is trivial. – kiss my armpit Feb 1 '14 at 12:53
  • My question was not clear enought. – Tarass Feb 1 '14 at 13:46
  • Look carefully the difference with Mark Wibrow tikz solution: the first and the last points are not on the grid, it means that it isn't precise enought especialy to make a grid. Exactly the grid pstrciks does and you use for your example. With you solution, the vertical and horizontal lines don't match at crossing points. – Tarass Feb 2 '14 at 8:03

The “old” plain TeX actually does this out of the box in one line, without the need of external complex packages:

my text\leaders\hbox to 1em{\hss.\hss}\hfill other text

Other options are:

  • use \hskip 5cm instead of \hfill to produce a dotted line 5cm long
  • use \hbox to 0.1cm instead of hbox to 1em to change the dot separation to 1mm
  • use \cleaders instead of \leaders to center the leaders, instead of having them alined
  • use \xleaders to have the leaders expanded to fill out the entire space (in this case the separation provided is a lower limit only).
  • 1
    I need a tikz style like dotted densely, but with a way to prescribe the number of points in a cm. – Tarass Feb 1 '14 at 12:47

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.