3

Given the example below, the scope command doesn't shift the path that I have been drawing. The only way I can achieve the what I am trying to do is by using explicit coordinates, but it would be much easier to use the cell numbers from the matrix m.

\documentclass[border=1cm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,fit,calc, automata}
\usepackage{listofitems}

\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt}, %default radius will be 1pt. cross/.default={10pt}}

\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}] { & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ };

\draw (m-1-1.north west) rectangle (m-12-12.south east);

\foreach \i in {3,6,9} { \draw (m-\i-1.south west) -- (m-\i-12.south east); }

\foreach \j in {3,6,9} { \draw (m-1-\j.north east) -- (m-12-\j.south east); }

\path[draw,purple, dashed,very thick] (3.2,-5.8) node[circle,draw=purple!80, inner sep=1pt] {+} -- (-2.8,-5.8) node[circle,draw=purple!80, inner sep=1pt] {-} -- (-2.8,-2.8) node[circle,draw=purple!80, inner sep=1pt] {+} -- (3.2,-2.8) node[circle,draw=purple!80, inner sep=1pt] {-} -- (3.2,-5.8) node {};

\begin{scope}[xshift=-5mm,yshift=-15mm] \path[draw,purple, dashed,very thick] (m-3-1) node[circle,draw=purple!80, inner sep=1pt] {+} -- (m-3-10) node[circle,draw=purple!80, inner sep=1pt] {-} -- (m-12-10) node[circle,draw=purple!80, inner sep=1pt] {+} -- (m-12-1) node[circle,draw=purple!80, inner sep=1pt] {-} -- (m-3-1) node {}; \end{scope}

\end{tikzpicture}

\end{document}

John W. de Burgh
  • 1,245
  • 1
  • 7
  • 15

1 Answers1

4

You could transform the canvas:

\documentclass[border=1cm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,fit,calc, automata}
\usepackage{listofitems}

\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt}, %default radius will be 1pt. cross/.default={10pt}}

\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}] { & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ & & & & & & & & & & & \ };

\draw (m-1-1.north west) rectangle (m-12-12.south east);

\foreach \i in {3,6,9} { \draw (m-\i-1.south west) -- (m-\i-12.south east); }

\foreach \j in {3,6,9} { \draw (m-1-\j.north east) -- (m-12-\j.south east); }

\path[draw,purple, dashed,very thick] (3.2,-5.8) node[circle,draw=purple!80, inner sep=1pt] {+} -- (-2.8,-5.8) node[circle,draw=purple!80, inner sep=1pt] {-} -- (-2.8,-2.8) node[circle,draw=purple!80, inner sep=1pt] {+} -- (3.2,-2.8) node[circle,draw=purple!80, inner sep=1pt] {-} -- (3.2,-5.8) node {};

\begin{scope}[transform canvas={xshift=-5mm,yshift=-15mm}] \path[draw,purple, dashed,very thick] (m-3-1) node[circle,draw=purple!80, inner sep=1pt] {+} -- (m-3-10) node[circle,draw=purple!80, inner sep=1pt] {-} -- (m-12-10) node[circle,draw=purple!80, inner sep=1pt] {+} -- (m-12-1) node[circle,draw=purple!80, inner sep=1pt] {-} -- (m-3-1) node {}; \end{scope}

\end{tikzpicture}

\end{document}

enter image description here