3

Here is the code, which is working fine:

\begin{tikzpicture}[scale=0.3]
    \draw (1,2)-- (1,4) -- (8,4) -- (8,2) -- cycle;
    \draw (6,4) -- (8,4) -- (8,11) -- (6,11) -- cycle;
    \draw (6,11) -- (6,13) -- (13,13) -- (13,11) -- cycle;
    \node at (1,2) {\textbullet};
    \node at (13,13) {\textbullet};
    \node[below] at (1,2) {$(1,2)$};
    \node[above] at (13,13) {$(13,13)$};
\end{tikzpicture}

I am sure there must be a way to draw up the three rectangles in an effective way.

Also, how could I label the points (\textbullet) as well as the coordinates in a more compact way?

4

I assume, you want to optimize the code of the question. All these operations can be put in one \draw command. Then the command form \tikz instead of the environment can be used. The path construction can be simplified via rectangle.

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \tikz[scale=.3]\draw
    (1, 2)
    node {\textbullet}
    node[below] {$(1, 2)$}
    rectangle (8, 4)
    rectangle (6, 11)
    rectangle (13, 13)
    node {\textbullet}
    node[above] {$(13, 13)$}
  ;
\end{document}

Result

  • Nice! Another option not shorter but more compact: ... node [label=below:{$(1,2)$}] {\textbullet} ... – Ignasi Jun 12 '15 at 6:10
  • @Ignasi I have tried, but the distance is much larger. – Heiko Oberdiek Jun 12 '15 at 6:15
  • Ups. You're right, with label, textbullet node size places label far away, while with a second node the reference is a coordinate a not a node. – Ignasi Jun 12 '15 at 6:30
4

Just a possible solution. Instead of lines, use a rectangular node which fits desired coordinates. After that, place label and points using anchors.

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}[scale=0.3, box/.style={draw, inner sep=0pt, outer sep=0pt}]
    \node[fit={(1,2) (8,4)}, box] (a){};
    \node[fit={(6,4) (8,11)}, box] (b){};
    \node[fit={(6,11) (13,13)}, box] (c){};
    \draw[fill] (a.south west) circle (5pt) node[below] {$(1,2)$};
    \draw[fill] (c.north east) circle (5pt) node[above] {$(13,13)$};
\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

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