I have a serious problem right now understanding what the parameters of the draw command mean.
For a document about neural networks I want to make an example of a system detecting different simple letters and I wanted to draw those letters in a grid, where every pixel is visible.
Therefore, I wrote this:
\documentclass{article}
\usepackage{tikz}
\usepackage[ngerman]{babel}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\draw[step=1,black] (0, 0) grid (3, 3);
\foreach \x in {1,2,3}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {1,2,3}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\end{tikzpicture}
\label{figt}
\caption{\glqq T\grqq}
\end{figure}
\end{document}
which gives a perfectly fine grid. Exactly what I was looking for.
Now I wanted the fields [1, 0], [1, 1], [0, 2], [1, 2], [2, 2] to be filled out, so that a "T" is visible.
I thought it would be as simple as:
\draw[fill=black, opacity=.5] (1, 0) rectangle (1, 1);
thinking, that (1, 0) is the position (bottom, middle) and (1, 1) is the width of the rectangle.
But this ended up with an empty grid again. So, I thought, maybe tikz starts with 1, not zero. So I wrote:
\draw[fill=black, opacity=.5] (2, 1) rectangle (1, 1);
with the very same result: an empty grid. Then I changed the "1" in (2, 1) to a zero
\draw[fill=black, opacity=.5] (2, 0) rectangle (1, 1);
and it finally worked: I had one "pixel" filled. And I since I already tried (2, 1) and it did nothing, I tried (2, 2), which filled the center pixel. But why? What's with (2, 1)? I don't get it. Does it start with 0 at the y-axis and with 1 at the x-axis?
So, now there is only the "hat" of "T" left. I thought,
\draw[fill=black, opacity=.5] (2, 3) rectangle (1, 1);
might help me. But (with transparency enabled) I see, that this "re-fills" (2, 2). Why?
Trying to fill (0, 3) (the upper left I assume) I wrote:
\draw[fill=black, opacity=.5] (0, 3) rectangle (1, 1);
But this filled both cells, again, (0, 3) and (0, 2), so the "T" looks like this:
(source: saved.im)
(with this code:
\begin{tikzpicture}
\draw[step=1,black] (0, 0) grid (3, 3);
\foreach \x in {1,2,3}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {1,2,3}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw[fill=black, opacity=.5] (2, 0) rectangle (1, 1);
\draw[fill=black, opacity=.5] (2, 3) rectangle (1, 1);
\draw[fill=black, opacity=.5] (0, 3) rectangle (1, 1);
\end{tikzpicture}
)
I am very sure that this is not a fault in tikz or whatever, but just my ignorance of the internals of tikz and of how to use it. But right now, after about 1 hour of playing around creating this character (and still haven't succeeded with it), I kind of give up and am clueless. Is my interpretation of those characters so wrong? Or what mistake did I make over and over again?
Best Answer
You need to use
+(1,1)
or++(1,1)
(there is a difference between the two which is irrelevant in this case) to get the corner of the rectangle 1 unit up and and 1 unit right from the last point: