How To Draw Diagram In Latex
Create nodes in TikZ
In our example, we distinguish 2 types of shapes: a circle and 3 rectangles. These shapes can exist created using \node command. Here is an case:
\documentclass[border=0.2cm]{standalone} % More defined colors \usepackage[dvipsnames]{xcolor} % Required packet \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} \node[describe, circumvolve, minimum size=0.6cm, make full=Rhodamine!l ] (sum) at (0,0){}; \end{tikzpicture} \end{certificate}
The above code creates a node with name (sum) at the point with coordinates (0,0). To draw the node, we accept to add the selection draw to information technology and with circle option, we get a circle shape. Past default, a node corresponds to a rectangle.
We provided as well the minimum size of the node which is equal to 0.6cm. It should be noted that adding details to a node (text, prototype or fifty-fifty a tikz code) increases its size.
The node is filled with the colour Rhodamine!50 which is ane of the dvipsnames provided by xcolor package. For a total list, check the mail: Predefined LaTeX colors: dvipsnames.
Anchors of a node in TikZ
Each node has anchors which corresponds to points coordinates of the node border. A feature that is non provided past draw command with circle shape. Dissimilar anchors are shown in the side by side illustration where we use the name of the node and an angle or we use predefined anchors such as (north, south, east, westward, etc)
Now, we can draw easily the sum shape of the cake diagram by connecting the indicate (sum.n east) with the betoken (sum.south due west) through a direct line using depict command. The same for the points with coordinates (sum.south east) and (sum.north w). Here is the code:
\documentclass[border=0.2cm]{standalone} % More defined colors \usepackage[dvipsnames]{xcolor} % Required bundle \usepackage{tikz} \usetikzlibrary{positioning} \begin{certificate} \begin{tikzpicture} % Sum shape \node[depict, circle, minimum size=0.6cm, fill=Rhodamine!50 ] (sum) at (0,0){}; \draw (sum.north east) -- (sum.south west) (sum.due north west) -- (sum.south east); \end{tikzpicture} \end{certificate}
which yields the following analogy:
At present, it remains to add together the positive and negative signs. We tin place them as nodes relative to the center of the sum node. Here is the corresponding slice of code:
\node[left=-1pt] at (sum.center){\tiny $+$}; \node[below] at (sum.center){\tiny $-$};
Calculation these two lines to the previous code, we go the following result:
Nosotros added the option left=<value> to put the node at the left of the provided coordinates (sum.center) with an offset equals to the provided value. The aforementioned for the negative sign which is located beneath the eye of the sum node.
Relative positioning in TikZ
At present, we would like to create the controller block which corresponds to a rectangle filled with a gilded color and has the label C(s). This can be accomplished post-obit the aforementioned steps as to a higher place where we will create a node with describe option and specify its size. To avoid positioning the at specific coordinates (x,y), we will apply relative positioning with respect to the sum node. Check the following code:
\documentclass[edge=0.2cm]{standalone} % More defined colors \usepackage[dvipsnames]{xcolor} % Required bundle \usepackage{tikz} \usetikzlibrary{positioning} \begin{certificate} \begin{tikzpicture} % Sum shape \node[draw, circle, minimum size=0.6cm, make full=Rhodamine!l ] (sum) at (0,0){}; \depict (sum.north due east) -- (sum.southward w) (sum.north west) -- (sum.south eastward); \describe (sum.n east) -- (sum.southward w) (sum.north west) -- (sum.south east); \node[left=-1pt] at (sum.heart){\tiny $+$}; \node[beneath] at (sum.eye){\tiny $-$}; % Controller \node [draw, fill up=Goldenrod, minimum width=2cm, minimum height=1.2cm, right=1cm of sum ] (controller) {$C(s)$}; \end{tikzpicture} \end{document}
The above code creates a node with rectangular shape (default shape no demand to specify it) which has a minimum width =2cm and minimum pinnacle=2cm. The node is located at the right of the sum node with 1cm altitude. This is accomplished using the selection correct=1cm of sum. We saved the rectangle node with the name (controller) which will exist used for relative positioning of the organisation block H(s). Here is the obtained illustration:
Post-obit the same steps every bit higher up, nosotros can create the arrangement and the sensor blocks. Here is the corresponding code:
\documentclass[edge=0.2cm]{standalone} % More defined colors \usepackage[dvipsnames]{xcolor} % Required package \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} % Sum shape \node[draw, circle, minimum size=0.6cm, fill=Rhodamine!50 ] (sum) at (0,0){}; \depict (sum.north east) -- (sum.south west) (sum.north westward) -- (sum.south east); \draw (sum.due north eastward) -- (sum.south due west) (sum.north due west) -- (sum.due south e); \node[left=-1pt] at (sum.eye){\tiny $+$}; \node[below] at (sum.centre){\tiny $-$}; % Controller \node [draw, fill=Goldenrod, minimum width=2cm, minimum height=1.2cm, correct=1cm of sum ] (controller) {$C(s)$}; % System H(s) \node [depict, fill up=SpringGreen, minimum width=2cm, minimum height=one.2cm, correct=1.5cm of controller ] (system) {$H(s)$}; % Sensor block \node [depict, fill up=SeaGreen, minimum width=2cm, minimum superlative=1.2cm, below right= 1cm and -0.25cm of controller ] (sensor) {$1000(due south)$}; \cease{tikzpicture} \end{document}
Compiling this code yields:
The sensor is positioned at the right and below of the controller node using the option: below right= 1cm and -0.25cm of controller. It remains to connect these blocks with arrows.
Draw an arrow with text label
This is the easiest role in drawing a block diagram in LaTeX. We need to connect anchors of different nodes. Let's start by drawing an arrow between the sum and the controller blocks:
\describe[-stealth] (sum.east) -- (controller.west) node[midway,above]{$due east$};
This line of code draws a line from (sum.east) to (controller.west). The line ends with an arrowhead of stealth type (For more arrow tips, check the mail Exploring TikZ Arrows) . We added a label to the pointer using a node command, the label is positioned at the above the middle of the distance between two blocks. This has been achieved using midway choice. The adjacent table provides more details about positioning forth a path:
We can do the same between the controller block and the organization cake:
\draw[-stealth] (controller.east) -- (system.west) node[midway,to a higher place]{$u$};
For the output of the system, we will draw an arrow with ane.25cm length and we save the node at the middle of the pointer to use it for connecting the output with sensor cake. Here is the corresponding lawmaking:
\describe[-stealth] (system.east) -- ++ (ane.25,0) node[midway](output){} node[midway,above]{$y$};
The node is named (output) and we will depict a line from its center (output.eye) to the (sensor.east) with a perpendicular lines. To achieve the after, we apply |- (vertical then straight line) instead of --.
\draw[-stealth] (output.center) |- (sensor.east); \draw[-stealth] (sensor.west) -| (sum.south) node[near end,left]{$y_m$};
The due west ballast of the sensor is connected with the south of the sum node using the path operation -| (straight then vertical line).
The input reference corresponds to a labeled pointer which can exist drawn with the same manner every bit the output arrow.
Here is the Final code of the latex cake diagram:
\documentclass[border=0.2cm]{standalone} % More defined colors \usepackage[dvipsnames]{xcolor} % Required packet \usepackage{tikz} \usetikzlibrary{positioning} \brainstorm{document} \begin{tikzpicture} % Sum shape \node[draw, circle, minimum size=0.6cm, fill=Rhodamine!50 ] (sum) at (0,0){}; \draw (sum.north east) -- (sum.south west) (sum.north west) -- (sum.south east); \draw (sum.north east) -- (sum.south westward) (sum.north west) -- (sum.south due east); \node[left=-1pt] at (sum.center){\tiny $+$}; \node[beneath] at (sum.center){\tiny $-$}; % Controller \node [draw, fill=Goldenrod, minimum width=2cm, minimum acme=ane.2cm, correct=1cm of sum ] (controller) {$C(s)$}; % System H(s) \node [draw, fill=SpringGreen, minimum width=2cm, minimum height=ane.2cm, correct=one.5cm of controller ] (system) {$H(s)$}; % Sensor cake \node [describe, fill=SeaGreen, minimum width=2cm, minimum summit=1.2cm, below right= 1cm and -0.25cm of controller ] (sensor) {$G(s)$}; % Arrows with text label \draw[-stealth] (sum.east) -- (controller.west) node[midway,above]{$e$}; \draw[-stealth] (controller.due east) -- (arrangement.w) node[midway,above]{$u$}; \draw[-stealth] (arrangement.east) -- ++ (i.25,0) node[midway](output){}node[midway,higher up]{$y$}; \draw[-stealth] (output.center) |- (sensor.e); \draw[-stealth] (sensor.west) -| (sum.south) node[near end,left]{$y_m$}; \describe (sum.west) -- ++(-i,0) node[midway,in a higher place]{$y_{ref}$}; \end{tikzpicture} \end{document}
Optimize the lawmaking with tikzstyle command
You may remarked that all rectangular blocks accept the aforementioned dimension characteristics and to avoid repeating these options: draw, minimum width=2cm, minimum top=1.2cm, we can create a style with these options using the \tikzstyle command as follows:
\tikzstyle{block} = [ depict, minimum width=2cm, minimum superlative=i.2cm ]
We named the style every bit block and we tin can use information technology as an option in all unlike node commands respective to the controller, system and sensor blocks.
Source: https://latexdraw.com/block-diagram-in-latex-step-by-step-tikz-tutorial/
Posted by: milsapmustrien.blogspot.com
0 Response to "How To Draw Diagram In Latex"
Post a Comment