1

It is fairly easy to draw a dotted line from the north to the south coordinate of a fitted node:

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{matrix} \usetikzlibrary{fit,shapes.geometric,calc,matrix,math}

\begin{document}

\begin{tikzpicture} \matrix(m) [matrix of nodes, row sep=1ex, column sep=1ex, nodes in empty cells, nodes={draw, shape=rectangle,minimum height=5ex, anchor=center, minimum width=5ex},ampersand replacement=&] { a & 1 & x & o & 2 \ b & & & & 3 \ c & & & & y \ d & & & & 4 \ e & 5 & v & p & w \ }; \node[fit= (m-2-2.north west) (m-4-4.south east), draw=red,inner sep=0ex] (x) {}; \draw[loosely dotted] (x.north) -- (x.south); \end{tikzpicture}

\end{document}

enter image description here

It would be much better if I could fit a custom dot pattern by choosing the size and spacing of the dots especially if this was predefined as a style. This style could be part of the \node[fit...] command instead of requiring a \draw command.

Ted Black
  • 453
  • 2
  • 8
  • Would you like either to fill all the fit node with a pattern or to draw only a line like in the current answer or to draw the contour of the fit node with a customized pattern? – CarLaTeX Nov 21 '21 at 19:21
  • Just a line from north to south as in the current answer. Apologies for not being clear. – Ted Black Nov 21 '21 at 19:48
  • Don't worry, so you already have the correct answer :) – CarLaTeX Nov 21 '21 at 19:49

1 Answers1

2

The style dotted pattern was defined using the code from dotted-lines-in-tikz-with-round-dots

You can choose the color, the radius of the dots and their separation (first picture) or the style defined as default will be applied (second picture).

b

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{matrix} \usetikzlibrary{fit,shapes.geometric,calc,matrix,math} \usetikzlibrary{decorations.markings}

%%https://tex.stackexchange.com/questions/101262/dotted-lines-in-tikz-with-round-dots \pgfkeys{/tikz/.cd, circle color/.initial=black, circle color/.get=\circlecolor, circle color/.store in=\circlecolor, }

\tikzset{dotted pattern/.style args={#1 and #2}{% postaction=decorate, decoration={ markings, mark= between positions 0 and 1 step #2 with {\fill[radius=#1,\circlecolor] (0,0) circle;} } }, dotted pattern/.default={0.5pt and 1mm}, }

\begin{document}

\begin{tikzpicture} \matrix(m) [matrix of nodes, row sep=1ex, column sep=1ex, nodes in empty cells, nodes={draw, shape=rectangle,minimum height=5ex, anchor=center, minimum width=5ex},ampersand replacement=&] { a & 1 & x & o & 2 \ b & & & & 3 \ c & & & & y \ d & & & & 4 \ e & 5 & v & p & w \ }; \node[fit= (m-2-2.north west) (m-4-4.south east), draw=red,inner sep=0ex] (x) {}; \path [circle color=red, dotted pattern=1.2pt and 2mm] (x.north) -- (x.south); \end{tikzpicture}

\bigskip

\begin{tikzpicture} \matrix(m) [matrix of nodes, row sep=1ex, column sep=1ex, nodes in empty cells, nodes={draw, shape=rectangle,minimum height=5ex, anchor=center, minimum width=5ex},ampersand replacement=&] { a & 1 & x & o & 2 \ b & & & & 3 \ c & & & & y \ d & & & & 4 \ e & 5 & v & p & w \ }; \node[fit= (m-2-2.north west) (m-4-4.south east), draw=red,inner sep=0ex] (x) {}; \path [dotted pattern] (x.north) -- (x.south); \end{tikzpicture}

\end{document}

Simon Dispa
  • 39,141