13

I'm trying to create a picture for Instant Insanity problem. Here is my following code:

\begin{tikzpicture}
\matrix[nodes=draw]
{
; & \node{\LARGE R}; & ; & ;\\
\node{\LARGE R}; & \node[draw=white]{\LARGE B}; & \node{\LARGE G}; & \node{\LARGE W};\\
; & \node{\LARGE R}; & ; & ;\\
};
\end{tikzpicture}

The problem is, the node containing B has relatively thick border. This is due to border overlapping by surrounding nodes. How can I turn off drawing borders of node containing B ?

3

I think you need to draw the lines manually:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix(m)[matrix of nodes,nodes={minimum width=2em,font=\LARGE}]
{
  & R & & \\
R & B & G & W\\
  & R & & \\
};
\draw (m-3-2.south west) rectangle (m-1-2.north east);
\draw (m-2-1.south west) rectangle (m-2-4.north east);
\draw (m-2-3.south east) -- (m-2-3.north east);
\end{tikzpicture}
\end{document}

TikZ's matrix library is apparently necessary to access the nodes in a matrix.

Now you can take that and make it the replacement text of a macro so you won't have to type it over and over.

4
  • I don't know why. Edge thickness is not same everywhere!
    – user1553
    Dec 24 '10 at 9:28
  • @Sazzad: This is probably due to your pdf renderer (which has to fit the line to pixels on your screen). How does it look when you change the zoom level or print it?
    – Caramdir
    Dec 25 '10 at 16:49
  • @Caramdir : When I zoom sufficiently, all looks OK. I think you're right, because I face the same problem with rectangle command. Hence, I use 1pt line width to make it seem smoother. :P
    – user1553
    Dec 26 '10 at 11:13
  • At last I've drawn the cubes with rectangle commands, the picture looks nicer but the code is not. Should I paste it here and ask, whether anybody can make any macro out of it?
    – user1553
    Dec 26 '10 at 11:15
44

Use \node[draw=none]. From the TikZ manual (section 15.3 “Drawing a Path” in v2.10),

If the special color name none is given, this option causes drawing to be “switched off.” This is useful if a style has previously switched on drawing and you locally wish to undo this effect.

3
  • I tried that. The effect is not good. I mean the lower border of 'B' seem to be thinner than any other. Isn't there any other way?
    – user1553
    Dec 23 '10 at 22:43
  • I was just answering the question as posed. But now I see what you want to achieve, though I can't think of a simple solution at the moment.
    – Caramdir
    Dec 23 '10 at 23:30
  • 6
    This answer is so useful I apparently upvoted it years ago, and now wish to do so again.
    – Ryan Reich
    Aug 15 '13 at 5:20
1

If turning off drawing node border is desires, Caramdir's answer is correct. We should use draw=none or just not include draw inside node's options.

But from description, it seems that OP's real problem is that using matrix every node shows its own border and adjacent borders show a double width:

enter image description here

This problem can also be solved selecting convenient row and column separations. row sep=-\pgflinewidth and column sep=-\pgflinewidth. But be careful, this solution only works when all nodes have borders with equal line width.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix(m)[matrix of nodes,nodes={draw, minimum width=2em,font=\LARGE}, 
column sep=-\pgflinewidth, row sep=-\pgflinewidth
]
{
  & R & & \\
R & B & G & W\\
  & R & & \\
};
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy