Skip to content Skip to sidebar Skip to footer

Draw Line From Node to Circle

Introduction

TimZ is probably the most complex and powerful tool to create graphic elements in LaTeX. Starting with a simple example, this article introduces some basic concepts: cartoon lines, dots, curves, circles, rectangles etc.

Firstly, load the tikz package by including the line \usepackage{tikz} in the preamble of your document, and then draw a graphic using the tikzpicture surround.

                        \documentclass            {article}            \usepackage            {tikz}            \begin            {document}            \brainstorm            {tikzpicture}            \draw            [gray, thick]            (-ane,two) -- (2,-4);            \depict            [greyness, thick]            (-1,-1) -- (2,two);            \filldraw            [black]            (0,0) circumvolve (2pt) node[anchor=west]{Intersection point};            \finish            {tikzpicture}            \end            {document}          

 Open this example in Overleaf

This example produces the following output:

OLV2tikz1.png

In this example ii lines and 1 point are drawn. To add a line the command \draw[gray, thick] defines a graphic element whose color is gray and with a thick stroke. The line is actually divers by it'south ii endpoints, (-1,ii) and (2,-4), joined by --.

The bespeak is actually a circle drawn past \filldraw[black], this command volition non only describe the circle but fill up it using black. In this control the centre point (0,0) and the radius (2pt) are alleged. Next to the point is a node, which is actually a box containing the text intersection bespeak, and anchored at the due west of the point.

Information technology's of import to notice the semicolon ; used at the end of each draw control.

Note: The tikzfigure environment tin can be enclosed inside a figure or like surround. See the Inserting Images article for more information on this topic.

Bones elements: points, lines and paths

In this section we provide some examples showing how to create some basic graphic elements which tin be combined to create more elaborate figures.

                        \documentclass            {commodity}            \usepackage            {tikz}            \brainstorm            {document}            \begin            {tikzpicture}            \draw            (-two,0) -- (ii,0);            \filldraw            [greyness] (0,0) circle (2pt);            \draw            (-two,-2) .. controls (0,0) .. (2,-2);            \draw            (-2,2) .. controls (-1,0) and (1,0) .. (2,2);            \end            {tikzpicture}            \end            {document}          

 Open up this instance in Overleaf

This example produces the following output:

OLV2tikz2.png

There are iii basic commands in this example:

  • \describe (-2,0) -- (2,0); : This defines a line whose endpoint are (-two,0) and (2,0).
  • \filldraw [greyness] (0,0) circle (2pt); : The signal is created as a very small gray circle centred at (0,0) and whose radius is (2pt). The \filldraw command is used to draw elements and fill them with a specific colour. See the next section for more examples.
  • \draw (-two,2) .. controls (-ane,0) and (1,0) .. (two,ii); : Draws a Bézier curve. At that place are 4 points defining it: (-two,2) and (2,ii) are its endpoints, (-1,0) and (1,0) are control points that determine "how curved" information technology is. You can call up of these ii points as "attractor points".

Bones geometric shapes: Circles, ellipses and polygons

Geometric figures can exist constructed from simpler elements so allow's showtime with circles, ellipses and arcs.

                        \documentclass            {article}            \usepackage            {tikz}            \brainstorm            {document}            \begin            {tikzpicture}            \filldraw            [colour=ruddy!threescore, make full=ruby!5, very thick](-1,0) circle (1.5);            \fill            [blueish!50]            (2.five,0) ellipse (one.5 and 0.5);            \draw            [ultra thick, ->]            (6.5,0) arc (0:220:1);            \end            {tikzpicture}            \stop            {document}          

 Open this instance in Overleaf

This example produces the following output:

TikzEx3.png

  • \filldraw[color=cerise!60, fill=red!5, very thick](-ane,0) circle (i.5); : This command was used in the previous section to describe a point, but in this case there are some additional parameters inside the brackets. These are explained beneath:
    • color=red!lx : The colour of the ring around the circle is set to 60% red (lighter than "pure" ruddy). See the reference guide for a list of the default colours available in LaTeastwardX; also, encounter Using colours in LaTeX to learn how to create your ain colours.
    • fill=red!v : The circle is filled with an fifty-fifty lighter shade of crimson.
    • very thick : This parameter defines the thickness of the stroke. See the reference guide for a complete list of values.
  • \fill[blue!l] (2.v,0) ellipse (1.5 and 0.five); : To create an ellipse you lot provide a centre point (two.5,0), and two radii: horizontal and vertical (1.5 and 0.5 respectively). Also detect the control fill instead of draw or filldraw, this is because, in this case, there's no need to control outer and inner colours.
  • \draw[ultra thick, ->] (6.five,0) arc (0:220:i); : This control will draw an arc starting at (6.five,0). The extra parameter -> indicates that the arc will have an arrow at the stop. In addition to the starting point y'all must provide 3 additional values: the starting and ending angles, and the radius; hither, these three parameter values are provided in the format (0:220:1).

In addition to curved geometric shapes you lot can likewise create elements that use direct lines, using a similar syntax:

                        \documentclass            {article}            \usepackage            {tikz}            \begin            {document}            \begin            {tikzpicture}            \draw            [blue, very thick]            (0,0) rectangle (3,two);            \draw            [orange, ultra thick]            (4,0) -- (6,0) -- (v.7,ii) -- bike;            \end            {tikzpicture}            \end            {document}          

 Open this case in Overleaf

This example produces the following output:

OLV2tikz4.png

  • \depict[blue, very thick] (0,0) rectangle (three,2); : Rectangles are created by the special command rectangle. You take to provide two points, the get-go i is where the "pencil" begins to draw the rectangle and the second one is the diagonally opposite corner betoken.
  • \depict[orangish, ultra thick] (4,0) -- (vi,0) -- (v.7,ii) -- cycle; : To draw a polygon we draw a closed path of direct lines: a line from (4,0) to (6,0) and a line from (6,0) to (v.vii,2). The wheel education ways that the start and end points should coincide to create a "closed" path (shape), which results in construction of the final line segment.

Diagrams

Nodes are probably the near versatile elements in TikZ. We've already used 1 node in the introduction—to add some text to the figure. The adjacent instance uses nodes to create a diagram.

                        \documentclass            {article}            \usepackage            {tikz}            \usetikzlibrary            {positioning}            \brainstorm            {document}            \begin            {tikzpicture}[ roundnode/.style={circumvolve, depict=greenish!60, make full=greenish!v, very thick, minimum size=7mm}, squarednode/.style={rectangle, draw=red!60, fill=carmine!v, very thick, minimum size=5mm}, ]            %Nodes            \node            [squarednode]            (maintopic)            {2};            \node            [roundnode]            (uppercircle)       [above=of maintopic]            {ane};            \node            [squarednode]            (rightsquare)       [right=of maintopic]            {3};            \node            [roundnode]            (lowercircle)       [beneath=of maintopic]            {4};            %Lines            \describe            [->]            (uppercircle.south) -- (maintopic.due north);            \draw            [->]            (maintopic.e) -- (rightsquare.w);            \describe            [->]            (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.due east);            \terminate            {tikzpicture}            \end            {document}          

 Open this case in Overleaf

This case produces the following output:

OLV2tikz5.png

There are essentially iii commands in this figure: A node definition, a node declaration and lines that bring together two nodes.

  • roundnode/.style={circle, draw=green!60, fill up=light-green!5, very thick, minimum size=7mm} : Passed as a parameter to the tikzpicture environment. Information technology defines a node that will be referenced as roundnode: this node volition be a circle whose outer band will be fatigued using the colour green!lx and will be filled using green!5. The stroke volition be very thick and its minimum size is 7mm. The line below this defines a second rectangle-shaped node called squarednode, using similar parameters.
  • \node[squarednode] (maintopic) {2}; : This will create a squarednode, as divers in the previous command. This node will accept an id of maintopic and will contain the number two. If you get out an empty space within the braces no text volition be displayed.
  • [above=of maintopic] : Find that all just the first node take an additional parameter that determines its position relative to other nodes. For instance, [above=of maintopic] ways that this node should appear above the node named maintopic. For this positioning organisation to work y'all have to add \usetikzlibrary{positioning} to your preamble. Without the positioning library, you tin use the syntax above of=maintopic instead, but the positioning syntax is more than flexible and powerful: you tin can extend it to write above=3cm of maintopic i.e. control the actual distance from maintopic.
  • \draw[->] (uppercircle.south) -- (maintopic.north); : An arrow-like direct line will exist fatigued. The syntax has been already explained in the basic elements section. The only difference is the manner in which we write the endpoints of the line: past referencing a node (this is why we named them) and a position relative to the node.

Reference Guide

Possible color and thickness parameters in the tikz package:

parameter values picture
color white, blackness, carmine, green, blue, cyan, magenta, yellow BasicColours.png
thickness ultra thin, very thin, sparse, thick, very thick, ultra thick Thickness.png

More colours may be available in your LaTeX distribution. Meet Using colours in LaTeX

Farther reading

For more data see:

  • Using colours in LaTeX
  • Pgfplots package
  • Inserting Images
  • Lists of tables and figures
  • Positioning images and tables
  • Drawing diagrams directly in LaTeX
  • The TikZ and PGF Packages Manual
  • TikZ and PGF examples at TeXample.cyberspace

jonesthavengetter1940.blogspot.com

Source: https://www.overleaf.com/learn/latex/TikZ_package

Postar um comentário for "Draw Line From Node to Circle"