Draw Half Circle in Latex
Tutorial 17.1a - PGF/Tikz
17 Nov 2018
Preamble
Tikz is a syntax that operates over the basic command set of Portable Graphics Format (PGF) that collectively provide routines for producing graphics within LaTeX. Most LaTeX distributions come bundled with PGF/Tikz. As Tikz is a LaTeX library, it is patently important that yous have some familiarity with LaTeX. Please ensure that you have explored Tutorial 17.ane.
The Tikz surround can be placed in any LaTeX document. For the purpose of focusing purely on Tikz, all demonstrations in this tutorial volition create stand-solitary figures (that is, graphics that are not embedded in other documents). Nevertheless, the aforementioned lawmaking could be used within a larger document code set.
Furthermore, whilst the first couple of code snippets (those in Section two: Minimum syntax) will include the full LaTeX code including the documentclass specification, preamble and document environment initialization, all remaining code volition be truncated to just the tikzpicture environment.
Minimum syntax
The following minimum syntax only produces a diagonal line. The syntax'south are intended as templates effectually which to construct more noun code.
LaTeX code | PDF effect |
---|---|
\documentclass{standalone} \usepackage{tikz} \brainstorm{document} \begin{tikzpicture} \draw (0,0) -- (1,one); \terminate{tikzpicture} \end{document} | |
In the above, the tikzpicture environs defined in the tikz package prepares the sheet for graphical instructions. The line starting with the \draw kwyword is an instance of a tikz instruction.
I will go into more detail about the \depict keyword later in the tutorial, withal as this routine is used to help outline the concepts of coordinates, I should clarification is necessary. \draw draws a line betwixt 2 points (coordinates). The syntax is \describe keyword first (coordinate) two dashes (--) second (coordinate) and the statement is completed by a semi-colon (;).
A more than complete minimum example that loads upward more tikz extension libraries (those that build on tikz), would be:
LaTeX code | PDF result |
---|---|
\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{arrows,shadows,positioning,mindmap} \usetikzlibrary{decorations, decorations.pathreplacing,decorations.pathmorphing} \usetikzlibrary{shapes,shadings,shapes.geometric, shapes.multipart,patterns} \usetikzlibrary{backgrounds,calc,fit} \brainstorm{document} \begin{tikzpicture} \depict (0,0) -- (1,1); \end{tikzpicture} \terminate{document} | |
The tikzpicture environment
The bones structure of the tikzpicture environment is as follows:
+\northward brainstorm{tikzpicture}[] (tikz commands); \end{tikzpicture}
The options utilise to any and all of the elements within the graphic (unless they are specifically overridden by the element). There are approximately 750 options that can exist practical to graphical elements (and thus the tikzpicture environment). Some of the most common options that are applied at the environment level and so that they affect all elements therein include:
Choice | Description |
---|---|
scale=(factor) | Rescaling the graphic by X (e.g. scale=2.five) |
xscale=(factor), yscale=(factor) | Rescaling x and y separately |
Coordinates
To help demonstrate coordinate concepts, I volition brand utilize of an inbuilt grid that tin can be placed on a graphic. This grid makes information technology easier to visualize the coordinate system and is therefore a helpful device.
LaTeX lawmaking | PDF effect |
---|---|
Generate a grid from (-2,-2) to (2,2) - (0,0) in the eye\begin{tikzpicture} \depict [help lines] (-2,-ii) filigree (2,2); \cease{tikzpicture} | |
Specifying
Coordinates are specified in brackets
Cartesian: comma separated (x,y)
Polar: colon separated (length:angle)
By default, the units are in centimeters for Cartesian (centimeters and degrees for Polar), still, all other valid LaTeX length units tin can exist used.
(2,four) (1pt,5cm) (2em,6mm)
LaTeX code | PDF result |
---|---|
Depict a line starting in the top correct corner (2,2) down to the the coordinate (i,-1) \brainstorm{tikzpicture} \draw [help lines] (-2,-two) filigree (2,2); \draw (2,2) -- (1,-1cm); \terminate{tikzpicture} | |
A positive x value is to the right, a positive y value is upwards.
Relative coordinates
Coordinates relative to the previous position tin be specified by appending either ++ (incremental) or + (non=incremental) earlier the brackets.
Relative coordinates | Description | Examples | |
---|---|---|---|
Incremental (++) | Motion from previous point and set the new reference location equally the current point | +\n brainstorm{tikzpicture} +\northward draw [help lines] (-2,-ii) grid (ii,2); +\n depict (2,2) -- ++(-1,-3cm) -- ++(-2,-1); +\due north cease{tikzpicture} | |
Non-incremental (+) | Move from previous point only do non gear up the new reference location as the electric current indicate | +\north begin{tikzpicture} +\n draw [help lines] (-2,-2) grid (2,2); +\due north draw (two,2) -- +(-1,-3cm) -- +(-2,-1); +\due north end{tikzpicture} |
Storing coordinates
Coordinates can be stored and referenced in other elements.
LaTeX code | PDF result |
---|---|
\begin{tikzpicture} \draw [aid lines] (-ii,-2) grid (2,2); \coordinate (A) at (1,1); \depict (A) -- ++(1,0); \finish{tikzpicture} | |
The coordinate specifier tin can besides be used straight afterward a coordinate is indicated and then as to store that coordinate.
LaTeX code | PDF consequence |
---|---|
\brainstorm{tikzpicture} \depict [aid lines] (-2,-2) grid (2,2); \draw (0,0) -- (one,1) coordinate (A); \draw (A) -- ++(1,0); \end{tikzpicture} | |
Modifying coordinates - coordinate calculations
Coordinates can themselves be more complex operations on coordinates. This is supported past the calc tikz extension package. The general syntax for coordinate calculations is:
($<gene*><coordinate calculations>$)
The coordinate calculations can then accept a series of at to the lowest degree i of the post-obit separated by + or -:
<factor*><coordinate><modifiers>
The post-obit table outlines the above syntax with each of the major coordinate modification types.
Projection
Coordinate modifier | Description | Examples | |
---|---|---|---|
Factors | Optional multipliers | +\n begin{tikzpicture} +\n draw [help lines] (-ii,-ii) filigree (2,2); +\n draw (0,0) -- ($ii*(1,ane)$); +\n depict (-ane,1) -- (${iii*(one-0.9)}*(1,1)$); +\n end{tikzpicture} | |
Addition/subtraction | Prepare a coordinate to be relative to specified coordinate | +\north brainstorm{tikzpicture} +\n draw [assistance lines] (-2,-2) grid (2,2); +\n draw (0,0) -- (1,1) coordinate (A); +\n draw ($(A) +(0,-ane)$) -- ++(1,0); +\n end{tikzpicture} | |
Fractional Partway | Fix a coordinate to exist a fraction of the distance partway between ii coordinates | +\n brainstorm{tikzpicture} +\northward draw [assist lines] (-ii,-2) filigree (ii,two); +\n draw (0,0) coordinate (A) -- (1,i) coordinate (B); +\due north draw ($(A) !0.5! (B)$) -- ++(1,0); +\n stop{tikzpicture} | |
Use fractional partway to get a length then specify a relative bending from the first coordinate | +\due north begin{tikzpicture} +\n draw [assistance lines] (-2,-2) grid (2,2); +\n draw (0,0) coordinate (A) -- (one,1) coordinate (B); +\n draw ($(A) !0.5!-90: (B)$) -- (ane,-i); +\northward finish{tikzpicture} | | |
Altitude Partway | Set a coordinate to be a specified distance from the first coordinate along a partway between two coordinates | +\n begin{tikzpicture} +\north draw [help lines] (-2,-2) grid (2,2); +\northward draw (0,0) coordinate (A) -- (ane,i) coordinate (B); +\n draw ($(A) !0.5cm! (B)$) -- ++(ane,0); +\n stop{tikzpicture} | |
Use distance partway to become a length and then specify a relative angle from the showtime coordinate | +\n begin{tikzpicture} +\due north draw [help lines] (-2,-two) filigree (2,two); +\due north draw (0,0) coordinate (A) -- (1,i) coordinate (B); +\n describe ($(A) !0.5cm!-ninety: (B)$) -- (1,-ane); +\n terminate{tikzpicture} | | |
Get to a coordinate along the path between the start and stop coordinate that is orthogonal to the projection coordinate | +\n begin{tikzpicture} +\n draw [help lines] (-2,-2) grid (2,2); +\north draw (0,0) coordinate (A) -- (one,one) coordinate (B); +\north coordinate (C) at (one,0); +\n describe ($(A) !(C)! (B)$) -- (1,-1); +\due north terminate{tikzpicture} | |
Lines and Paths
A path is a series of line segments (direct or curved) betwixt coordinates and is specified by the \path command. Past default, a path is invisible.
Options | Clarification | Examples | |
---|---|---|---|
Path Actions | draw fill pattern shade \draw is the same as \path [depict] etc | +\n brainstorm{tikzpicture} +\n draw [help lines] (-2,-2) grid (2,2); +\northward path [draw] (0,0) -- (1,1); +\n path [fill up] (0,0) -- (i,0) -- (0,-1); +\north path [pattern] (-2,0) -- (-1,0) -- (-2,-one); +\n path [shade] (0,-1) -- (1,-i) -- (0,-2); +\northward cease{tikzpicture} | |
Geometric Actions | rotate=<angle> xshift=<length> yshift=<length> scaling=<factor> xscale=<factor> yscale=<factor> | +\n brainstorm{tikzpicture} +\n draw [help lines] (-2,-two) grid (2,ii); +\due north draw (-2,2) -- (-1,2) -- (-two,one); +\north draw [rotate effectually={45:(i,two)}] (0,2) -- (i,two) -- (0,one); +\due north draw [xshift=-1cm] (0,one) -- (ane,1) -- (0,0); +\due north depict [xscale=2] (0,-1) -- (1,-1) -- (0,-2); +\north end{tikzpicture} | |
Color | color=<colour proper noun> draw=<line color> fill=<fill up color> opacity=<factor> | +\north brainstorm{tikzpicture} +\north draw [help lines] (-2,-2) grid (ii,2); +\n draw [color=cherry] (0,two) -- (1,2) -- (0,1); +\n draw [fill=green!50] (0,one) -- (ane,1) -- (0,0); +\northward draw [opacity=0.v] (0,-1) -- (1,-1) -- (0,-2); +\due north end{tikzpicture}Named colors | |
Line width | line width=<dimension> ultra thin very sparse thin semithick thick very thick ultra thick | +\n brainstorm{tikzpicture} +\n draw [help lines] (-2,-2) filigree (2,two); +\n draw [very thick] (0,two) -- (i,2) -- (0,1); +\n describe [line width=4pt] (0,1) -- (i,one) -- (0,0); +\n draw [thin] (0,-ane) -- (1,-1) -- (0,-2); +\due north end{tikzpicture}Named colors | |
Line blazon | solid dashed dotted dashdotted densely dotted loosely dotted double dash pattern=<design> nuance phase=<stage> | +\northward begin{tikzpicture} +\northward draw [aid lines] (-2,-2) filigree (2,two); +\north draw [dashed] (0,2) -- (1,2) -- (0,ane); +\north draw [loosely dotted] (0,one) -- (1,1) -- (0,0); +\n draw[densely dashed] (0,-1) -- (1,-1) -- (0,-ii); +\n end{tikzpicture}Named colors | |
Direct paths/lines
Lines can be fatigued by either using the draw path option or the \draw keyword.
LaTeX lawmaking | PDF result |
---|---|
+\n begin{tikzpicture} +\northward depict [help lines] (-2,-2) grid (2,2); +\n path [draw] (-ane,ane) -- (1,2); +\n draw (-ane,-1) -- (1,0) -- (one,-1); +\north terminate{tikzpicture} | |
A path tin can be closed with the --cycle performance
LaTeX lawmaking | PDF result |
---|---|
+\n brainstorm{tikzpicture} +\n describe [aid lines] (-two,-2) filigree (2,2); +\northward draw (-1,-1) -- (ane,0) -- (one,-i) --cycle; +\n end{tikzpicture} | |
Points tin be connected past an 'elbow' including only a horizontal and vertical line rather than a single straight line.
LaTeX code | PDF result |
---|---|
+\n begin{tikzpicture} +\northward draw [assist lines] (-ii,-2) grid (2,2); +\n draw (-1.5,2) |- (0.0,-0.5); +\n draw (-1,0.8) -| (1.five,-1.five); +\northward cease{tikzpicture} | |
Bezier curved paths/lines
Bazier curves are specified by including .. controls () .. control between points. The coordinates of the controls ascertain the Bezier bend handles.
LaTeX lawmaking | PDF upshot |
---|---|
\begin{tikzpicture} \depict [help lines] (-2,-2) grid (2,ii); \draw (-ane.v,0) .. controls (-1,1) .. (1,-0); \draw (-one.5,-0.5) .. controls (-ane,-i) and (0,-ane) .. (one,-0.5); \end{tikzpicture} | |
Other curves
It is also possible to create parabola curved paths/lines by a to operation. Exit and entry angles can be respectively divers by the out= and in= options. Alternatively, the bend option can exist used to signal the direction (left or right) and angle of a bend in the path/line. Likewise consider the post-obit options
- (in,out) looseness
- (in,out) (min,max) distance
- (in,out) control
LaTeX code | PDF result |
---|---|
\begin{tikzpicture} \draw [help lines] (-2,-2) grid (ii,2); \draw (-one.5,0) to [out=45,in=180] (i,-0); \describe (-one.5,-0.five) to[bend right=20] (1,-0.five); \end{tikzpicture} | |
Arc paths/lines
Arcs(of circles or elipses) are achieved via the arc control. An arc is divers by iii parameters separated past colons:
(out bending;in angle;radius length). If only a single radius length is given, an arc is drawn, if two radius lengths are given, an ellipse is drawn. The sign of the radius determines the orientation of the arc.
LaTeX code | PDF issue |
---|---|
+\north begin{tikzpicture} +\n draw [help lines] (-2,-2) grid (2,ii); +\n depict (-1.5,0.v) arc (10:300:-0.75cm); +\north draw (-1.5,-i) arc (10:300:-0.75cm and 0.75cm); +\n draw (0,0) arc (10:300:-1cm and -0.5cm); +\n end{tikzpicture} | |
Uncomplicated shape paths/lines
At that place are some pre-defined shapes.geometric
LaTeX code | PDF result |
---|---|
+\due north begin{tikzpicture} +\n draw [assistance lines] (-2,-2) grid (2,2); +\northward draw (-ane.5,1.5) rectangle (1.5,0.5); +\n draw(0,0) circle (one); +\n draw (0,-0.5) ellipse (0.5 and one); +\n end{tikzpicture} | |
Uncomplicated path/line options
Options | Description | Examples | |
---|---|---|---|
color | color of the lines. Can be a mixture of colors. Missing color value treated as 100, missing color treated as white. | \begin{tikzpicture} \draw [assist lines] (-2,-2) filigree (2,2); \draw [colour=cerise!80!black] (-1.5,one) -- (ane,one.5); \draw [color=red!xl] (-i,1) -- (i,0.5); \describe [color=red] (-one.five,-1.v) rectangle (ane.5,-0.5); \end{tikzpicture}Named colors | |
fill | colour of the fill. Can exist a mixture of colors. Missing color value treated every bit 100, missing colour treated as white. Named colors same every bit color | \begin{tikzpicture} \draw [help lines] (-2,-ii) grid (two,ii); \draw[fill=green] (-one.5,0.5) arc (ten:300:-0.75cm); \describe[fill=cherry-red!l] (-ane.5,-1.v) rectangle (ane.5,-0.5); \cease{tikzpicture} | |
-> etc | Arrow heads and tails | +\north begin{tikzpicture} +\north depict [aid lines] (-2,-two) grid (2,2); +\northward draw [<->] (-1.five,0.5) arc (10:300:-0.75cm); \draw [|->] (-1.five,-ane.5) -- (1.v,-0.5); \terminate{tikzpicture}Named colors | |
thin, thick etc | Line thickness | \begin{tikzpicture} \draw [help lines] (-2,-2) grid (2,2); \draw [thin] (-1.5,0.5) arc (10:300:-0.75cm); \depict [very thick] (-1.v,-i.five) -- (i.v,-0.5); \end{tikzpicture}Named colors | |
dashed, dotted etc | Line type | \brainstorm{tikzpicture} \draw [assist lines] (-2,-2) grid (2,2); \depict [dashed] (-1.5,0.5) arc (10:300:-0.75cm); \draw [dotted] (-1.5,-one.v) -- (1.5,-0.v); \terminate{tikzpicture}Named colors | |
rounded corners | Rounded corners | \begin{tikzpicture} \draw [aid lines] (-ii,-2) filigree (two,two); \depict[rounded corners] (-ane.5,0.five) |- (i.v,-0.25); \draw[rounded corners=15pt] (-1.5,-2) |- (1.5,-0.5); \end{tikzpicture} | |
Nodes
A node is a text element placed at a coordinate and optionally may have a simple shape (such as a rectangle or elipse) drawn around it. By default, the shape around a node is stretched such that it just slightly bigger than the contents. A node has a number of anchors besides as a label that can be used to refer to the node (or whatever of its anchors).
A node has the post-obit syntax:
\node [<options>] (<name>) {<text>};
where the optional name is the node'south label and the optional text is the text element to announced at the node.
LaTeX code | PDF effect |
---|---|
+\n begin{tikzpicture} +\n describe [help lines] (-2,-2) grid (2,2); +\n node at (-1,1) (NodeA) {Node A}; +\north node at (1,-1) (NodeB) {Node B}; +\northward end{tikzpicture} | |
Nodes can likewise exist defined along a path/line by using the node operator in a similar way to the coordinates operator.
LaTeX code | PDF result |
---|---|
+\n begin{tikzpicture} +\n draw [help lines] (-two,-two) filigree (2,2); +\due north path [draw] (-1,one) node (NodeA) {Node A} -- (1,-i) node (NodeB) {Node B} -- (-one,-1.5); +\n end{tikzpicture} | |
Nodes can be joined via their anchors
LaTeX code | PDF result |
---|---|
+\due north begin{tikzpicture} +\northward draw [help lines] (-two,-two) filigree (ii,2); +\n node at (-1,1) (NodeA) {Node A}; +\north node [draw] at (1,-ane) (NodeB) {Node B}; +\n draw (NodeA) -- (NodeB); +\n end{tikzpicture} | |
The following shapes are bachelor:
For each of the shapes, there are a number of anchors are available. The following cascading list features figures modified from the excellent pgf manual that illustrate the anchors associated with each shape.
The diverse coordinate modifiers outlined in Section 2 above tin can also be used to create new coordinates from these anchors.
Node options
Options | Description | ||
---|---|---|---|
Inner separation | Space between text element and node shape boundary inner sep=<dimension>
| ||
Outer separation | Space between node shape boundary and anchors outer sep=<dimension>
| ||
Anchor location | Anchor location anchor=<direction> or where direction is one of 'north','south','east','west' or a combination <direction>=of <node>
| ||
Minimum size | Minimum peak and/or width minimum size=<dimension>, minimum width=<dimension>, minimum pinnacle=<dimension> This provides a fashion of ensuring that the size of the node is not solely dependent on the size of the node contents.
| ||
Shape aspect ratio | The aspect ratio of shapes. This allows a square minimum size=<dimension>, minimum width=<dimension>, minimum height=<dimension> This provides a fashion of ensuring that the size of the node is not solely dependent on the size of the node contents.
|
Source: https://www.flutterbys.com.au/stats/tut/tut17.1a.html
0 Response to "Draw Half Circle in Latex"
Postar um comentário