1

enter image description here

I know how to draw grid as the above figure. But don't know how to position A(0, 0), (x, 0), B(x, y), (0, y) at (0, 0), (5, 0), (5, 4), (0, r) respectively.

I know how to draw a connected rectangles, but don't know how to draw a distinguishable path on the grid as the above picture. Does anybody know how to make the above picture?

When I try rectangles to make some similar path in the below code it doesn't appear.

\documentclass{article}  
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \draw[step=1cm, color=gray] (0, 0) grid (5, 4);
\end{tikzpicture}
\end{document}
3

As far as the four angles are concerned, I'd use a \foreach with some simple code for positioning. Technically, you could just write four node commands, it depends on the situation and personal taste.

For the path, just use a \draw command with coordinates. These are the coordinates:

enter image description here

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}  
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \draw[step=1cm, color=gray] (0, 0) grid (5, 4);

\foreach \coord/\label [count=\xi] in {
    {0,0}/{$A(0, 0)$},
    {5,4}/{$B(x, y)$},
    {5,0}/{$(x, 0)$},
    {0,4}/{$(0, y)$}
}{
    \pgfmathsetmacro\anch{mod(\xi,2) ? "north" : "south"}
    \node[anchor=\anch] at (\coord) {\label};
}

\draw[line width=3pt, rounded corners] (0,0) -- (0,1) -- (3,1) -- (3,2) -- (5,2) -- (5,4);

\end{tikzpicture}
\end{document}
| improve this answer | |
  • The code is really helpful. I'm really a beginner as to using Texworks. When I opened some readme files of Miktex and Tikz, there were some conditions about license and copyright so I depended on this website to learn how to draw some graphs and diagrams. Do you know some other websites for a drawing tutorial? tug.org/TUGboat/tb28-1/tb88mertz.pdf – buzzee Mar 20 '16 at 12:26
  • @buzzee Tutorial for Tikz? – Alenanno Mar 20 '16 at 12:29
  • Yes. Yes! The more comprehensive the tutorial, the better. – buzzee Mar 20 '16 at 12:37
  • @buzzee Never had to use a tutorial to be honest. I learned using this site, first asking some questions, then answering. :D – Alenanno Mar 20 '16 at 14:12
  • 2
    @buzzee You already have a good tutorial in your system. Open a terminal window and type command texdoc pgfmanual and start reading from page 28. An alternative could be reading from texdoc.net – Ignasi Mar 20 '16 at 17:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.