11

The following are the standard anchors available in TikZ (to the best of my knowledge):

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{dot/.style = {
    shape  = circle,
    draw   = black,
    fill = black,
    minimum size = 0.2cm
}}

\tikzset{squarenode/.style = {
        shape  = rectangle,
        draw   = black,
        minimum height = 10cm,
        minimum width  = 10cm
}}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {};
  \node[label=a.center] at (a.center) [dot] {};
  \node[label=a.north] at (a.north) [dot] {};
  \node[label=a.south] at (a.south) [dot] {};
  \node[label=a.east] at (a.east) [dot] {};
  \node[label=a.west] at (a.west) [dot] {};
  \node[label=a.north east] at (a.north east) [dot] {};
  \node[label=a.north west] at (a.north west) [dot] {};
  \node[label=a.south east] at (a.south east) [dot] {};
  \node[label=a.south west] at (a.south west) [dot] {};
\end{tikzpicture}
\end{document} 

Now, how do I locate the following points:

  1. Point between a.south and a.south west (midpoint and normal point - any point on the line)
  2. Point between a.south west and a.center (midpoint and normal point - any point on the line)
  • 1
    If you want to add new anchors to an existing shape, see tex.stackexchange.com/q/14769/86 – Loop Space Mar 29 at 6:59
  • There are also .base, .base east, .base west and all the .<angle> for the standard rectangle shape. – Kpym Mar 29 at 10:17
12

You can gan get points on a line between two nodes with coordinate[pos=x], where x is a fraction. so

\path (a.south west) -- (a.south) coordinate[pos=0.5] (a-mid-sw);

will give you the point in the middle between (a.south west) and (a.south). If you choose x smaller/larger, it will be closer to (a.south west)/(a-mid-sw), and for x=0 or x=1 it will coincide with (a.south west) or (a.south) respectively. Note that x can be negative or larger than 1, in which case the coordinate will be located outside the line connecting the points.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{dot/.style = {
    shape  = circle,
    draw   = black,
    fill = black,
    minimum size = 0.2cm
}}

\tikzset{squarenode/.style = {
        shape  = rectangle,
        draw   = black,
        minimum height = 10cm,
        minimum width  = 10cm
}}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {};
  \node[label=a.center] at (a.center) [dot] {};
  \node[label=a.north] at (a.north) [dot] {};
  \node[label=a.south] at (a.south) [dot] {};
  \node[label=a.east] at (a.east) [dot] {};
  \node[label=a.west] at (a.west) [dot] {};
  \node[label=a.north east] at (a.north east) [dot] {};
  \node[label=a.north west] at (a.north west) [dot] {};
  \node[label=a.south east] at (a.south east) [dot] {};
  \node[label=a.south west] at (a.south west) [dot] {};
  \path (a.south west) -- (a.south) coordinate[pos=0.5] (a-mid-sw)
(a.south west) -- (a.center) coordinate[pos=0.3] (a-diag);
  \node[label=a-mid-sw] at (a-mid-sw) [dot] {};
  \node[label=a-diag] at (a-diag) [dot] {};
\end{tikzpicture}
\end{document} 

enter image description here

The calc library also allows you to mix coordinates. And you can get points on the boundary using a.angle, where the angle has to be specified in degrees. a.90, for instance, is the same as a.north, a.0 the same as a.east but in general a.45 and a.north east do not have to coincide. (Here they do because the shape is a square.) If you want to have additional anchors, you may define a new shape.

7

Another way using calc library (node labels are inspired by marmot's answer)

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,calc}

\tikzset{dot/.style = {
    shape  = circle,
    draw   = black,
    fill = black,
    minimum size = 0.2cm
}}

\tikzset{squarenode/.style = {
        shape  = rectangle,
        draw   = black,
        minimum height = 10cm,
        minimum width  = 10cm
}}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {};
  \node[label=a.center] at (a.center) [dot] {};
  \node[label=a.north] at (a.north) [dot] {};
  \node[label=a.south] at (a.south) [dot] {};
  \node[label=a.east] at (a.east) [dot] {};
  \node[label=a.west] at (a.west) [dot] {};
  \node[label=a.north east] at (a.north east) [dot] {};
  \node[label=a.north west] at (a.north west) [dot] {};
  \node[label=a.south east] at (a.south east) [dot] {};
  \node[label=a.south west] at (a.south west) [dot] {};
  \node[label=a-mid-sw] at ($(a.south west)!.5!(a.south)$) [dot] {};
  \node[label=a-diag] at ($(a.south west)!.3!(a.center)$) [dot] {};
\end{tikzpicture}
\end{document} 

enter image description here

In case you are using this a lot, I suggest using a macro

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,calc}

\tikzset{dot/.style = {
    shape  = circle,
    draw   = black,
    fill = black,
    minimum size = 0.2cm
}}

\tikzset{squarenode/.style = {
        shape  = rectangle,
        draw   = black,
        minimum height = 10cm,
        minimum width  = 10cm
}}
\def\findmid#1#2#3{($(#2)!#1!(#3)$)}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
  \node (a) at (0,0) [squarenode] {};
  \node[label=a.center] at (a.center) [dot] {};
  \node[label=a.north] at (a.north) [dot] {};
  \node[label=a.south] at (a.south) [dot] {};
  \node[label=a.east] at (a.east) [dot] {};
  \node[label=a.west] at (a.west) [dot] {};
  \node[label=a.north east] at (a.north east) [dot] {};
  \node[label=a.north west] at (a.north west) [dot] {};
  \node[label=a.south east] at (a.south east) [dot] {};
  \node[label=a.south west] at (a.south west) [dot] {};
  \node[label=a-mid-sw] at \findmid{0.5}{a.south west}{a.south} [dot] {};
  \node[label=a-diag] at \findmid{0.3}{a.south west}{a.center} [dot] {};
\end{tikzpicture}
\end{document} 

(the same output as above)

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.