- up
- This document in PDF
Basic Tikz examples
Nasser M. Abbasi
January 28, 2024
All the tikz examples I see on the net are too complicated to learn from, so I am making
simple ones to help me learn from.
To draw x,y coordinates system
| |
\begin{tikzpicture}
\draw (0,0) -- (1,0);
\draw (0,0) -- (0,1);
\end{tikzpicture}
|
|
| |
To make the x,y axis arrows
| |
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[->] (0,0) -- (0,1);
\end{tikzpicture}
|
|
| |
To make the arrow heads larger (needs arrows.meta
)
| |
\begin{tikzpicture}
\draw[-{>[scale=3.0]}] (0,0) -- (1,0);
\draw[-{>[scale=3.0]}] (0,0) -- (0,1);
\end{tikzpicture}
|
|
| |
To make the arrow heads solid
| |
\begin{tikzpicture}
\draw[-{Latex[scale=2.0]}] (0,0) -- (1,0);
\draw[-{Latex[scale=2.0]}] (0,0) -- (0,1);
\end{tikzpicture}
|
|
| |
To make the axis red colored
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0);
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1);
\end{tikzpicture}
|
|
| |
To add labels on axis
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\end{tikzpicture}
|
|
| |
To draw line at 30 degrees of length 2 unit using cartesian coordinates
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw (0,0) -- ({2*cos(30)},{2*sin(30)});
\end{tikzpicture}
|
|
| |
To defined the line length as variable
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw let \n1={2} in (0,0) -- ({\n1*cos(30)},{\n1*sin(30)});
\end{tikzpicture}
|
|
| |
To use polar coordinates to draw the line
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw let \n1={2} in (0,0) -- (30:\n1);
\end{tikzpicture}
|
|
| |
To define the length of the line using the new evaluate
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw[evaluate={\r1=2;}] (0,0) -- (30:\r1);
\end{tikzpicture}
|
|
| |
To make the line an arrow
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw[->,evaluate={\r1=2;}] (0,0) -- (30:\r1);
\end{tikzpicture}
|
|
| |
To put label at end of line
| |
\begin{tikzpicture}
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (1,0) node [right] {$x$};
\draw[-{Latex[red,scale=2.0]}] (0,0) -- (0,1) node [above] {$y$};
\draw[->,evaluate={\r1=2;}] (0,0) -- (30:\r1) node [pos=1.1] {$v$};
\end{tikzpicture}
|
|
| |
Make a 2 link RR robot arm
| |
\def\L{1}
\def\w{\L/2}
\begin{tikzpicture}
%bottom link
\draw ({-\w/2},0) -- ({\w/2},0) -- ({\w/2},\L) -- ({-\w/2},\L) --cycle;
\draw ({\w/2},\L) arc (0:180:{\w/2});
%top link
\draw [shift={(0,{\L+\w/3})},rotate=45] ({\w/4},0) arc (0:-180:{\w/4});
\draw [shift={(0,{\L+\w/3})},rotate=45] ({\w/4},0) -- ({\w/4},\L) -- ({-\w/4},\L) -- ({-\w/4},0) --cycle;
\end{tikzpicture}
|
|
| |