Try to understand this code and you'll know how to draw all of them.
Start with definition of coordinates.
\coordinate (1) at (0,0,2);
creates a coordinate node
(node
without dimensions) named 1
at point (x,y,z)=(0,0,2)
. 2
means 2cm
. If you need some particular unit change cm
to mm
, in
, ... Later reference to point (0,0,2) will be done with (1)
. There is no need to remember its particular coordinates.
Second place circles in every coordinate and add labels to it.
\fill (1) circle (1pt) node [below] {1};
will draw and fill a circle with radious 1pt
(1 point) with center in coordinate 1
. Below it a node with text 1
is placed. Because points 1 to 4 has label below and 5 to 8 has it above, it's possible to use a foreach
loop.
Last, draw
lines between coordinates:
\draw[dashed] (1)--(4)--(3) (4)--(8);
draws a dashed
line from coordinate 1 to 4 and 3. Next places the pen on coordinate 4 and draws another line to coordinate 8.
You can use nodes
(coordinates
are nodes) to position other nodes. JLDiaz explained in his comments how to use calc
syntax (needs \usetikzlibrary{calc} in preamble) to do it:
\coordinate (17) at ($(1)!.5!(5)$);
defines a new coordinate 17
on "the point in the line (1)-(5) which is at 50% of the distance from (1)" (the !.5! means that 50%). One you have coordinate 17
defined you can apply again \fill (17) circle (1pt) node [left] {17};
to draw the circle and label.
An alternative syntax could be
\path (1) -- (5) coordinate[pos=0.5] (17);
which means move from 1
to 5
and in pos=0.5
from this path place a coordinate node named 17. This syntax doesn't use calc
library.
As an exercice: What do you think \coordinate (27) at ($(1)!.5!(7)$);
does?
Before the complete code a little suggestion. If you fill intimidated by TiKZ
huge documentation, take a look at some of documents recommended in
Now the complete code
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (1) at (0,0,2);
\coordinate (2) at (2,0,2);
\coordinate (3) at (2,0,0);
\coordinate (4) at (0,0,0);
\coordinate (5) at (0,2,2);
\coordinate (6) at (2,2,2);
\coordinate (7) at (2,2,0);
\coordinate (8) at (0,2,0);
\coordinate (17) at ($(1)!.5!(5)$);
\coordinate (27) at ($(1)!.5!(7)$);
\foreach \i in {1,...,4}
\fill (\i) circle (1pt) node [below] {\i};
\foreach \i in {5,...,8}
\fill (\i) circle (1pt) node [above] {\i};
\fill (17) circle (1pt) node [left] {17};
\fill (27) circle (1pt) node [above] {27};
\draw (1) --(2) --(3) --(7) --(6)--(5)--(8)--(7);
\draw (1)--(5) (2)--(6);
\draw[dashed] (1)--(4) --(3) (4)--(8);
\end{tikzpicture}
\end{document}

:-)
Asking questions about specific problems you're having on one figure often leads to faster and more learning-conducive answers. The question is then much more useful to future visitors to the site as well.`
, they'll be marked as code. You can also highlight the code and click the "code" button (with "{}" on it).