TikZ-PGF – Getting Values for Predefined Dash Patterns for Grid in Option Help Lines

gridstikz-pgf

dashed help lines

I would like to see other similar or different ways of resizing the strokes when drawing a grid with the help lines option when a dashed pattern is used. Here's an example below.

\documentclass{article}
\usepackage{tikz}
\tikzstyle{dashdotted}=[dash pattern=on 9pt off 2pt on \the\pgflinewidth off 2pt]
\begin{document}
\begin{tikzpicture}
\draw[help lines, dashdotted, xstep=1.3cm, ystep=1.6cm] (0,0) grid (16,8);
\end{tikzpicture}
\end{document}

I used this example:TikZ: Get values for predefined dash patterns

Best Answer

The styles listed in the post you linked are already defined in TikZ, you do not need to create a new style to use them.

You can create a style if you need a pattern that doesn't exist. For example, mygridstyle in my MWE creates a style with a sequence of dashes with a length of 8pt, 6pt, 4pt, and 2pt separated by a space of 4pt.

\documentclass{article}
\usepackage{tikz}
\tikzset{mygridstyle/.style={dash pattern=on 8pt off 4pt on 6pt off 4pt on 4pt off 4pt on 2pt off 4pt}}
\begin{document}
Standard dashdotted:
\begin{tikzpicture}
\draw[gray, dashdotted, xstep=1.3cm, ystep=1.6cm] (0,0) grid (4,4);
\end{tikzpicture}

Standard dotted, thick line:
\begin{tikzpicture}
\draw[gray, dotted, xstep=1.3cm, ystep=1.6cm, thick] (0,0) grid (4,4);
\end{tikzpicture}

Standard dash, with 4pt line width:
\begin{tikzpicture}
\draw[gray, dotted, xstep=1.3cm, ystep=1.6cm, line width=4pt] (0,0) grid (4,4);
\end{tikzpicture}

Customized sytle, very thick line:
\begin{tikzpicture}
\draw[gray, mygridstyle, xstep=1.3cm, ystep=1.6cm, very thick] (0,0) grid (4,4);
\end{tikzpicture}
\end{document}

enter image description here