can anyone guid me to plot the image in latex using tikz. i have shared the image file - latex

I want to draw this image in a latex file using tikz and pgfplots. I have no idea I to do it. i just need the exact image shown in the image file in latex code

The code below produces this:
the output figure
\documentclass[dvipdfmx]{article}
\usepackage{tikz,bm}\usetikzlibrary{arrows.meta, angles, quotes}
\begin{document}
\begin{tikzpicture}[>=stealth, x=6mm, y=6mm, thick]
\draw (-5.5,0) -- (5.5,0) node[right] {$\boldsymbol{x}$};
\draw (0,-5.5) -- (0,5.5) node[above] {$\boldsymbol{y}$};
\draw (5,0.1) -- (5,-0.1) node[below] {$\boldsymbol{5}$};
\draw (0.1,5) -- (-0.1,5) node[left] {$\boldsymbol{5}$};
\draw (-5,0.1) -- (-5,-0.1) node[below] {$\boldsymbol{5}$};
\draw (0.1,-5) -- (-0.1,-5) node[left] {$\boldsymbol{5}$};
\draw[-{Stealth[length=3mm]}] (0,0) -- (4,-3);
\node[below] at (2,-1.5) {$\mathbf{A}$};
\draw[dotted] (4,0) -- (4,-3);
\draw[dotted] (0,-3) -- (4,-3);
\node[right] at (4,-2) {$\boldsymbol{-3}$};
\node[below] at (2,-3) {$\boldsymbol{4}$};
\coordinate (a) at (0,0); \coordinate (b) at (1,0); \coordinate (c) at (2,-1.5);
\draw pic[draw, angle radius=0.8cm, "$\boldsymbol{\alpha}$" shift={(0.2,-0.1)}] {angle=c--a--b};
\end{tikzpicture}
\end{document}

Related

How to draw a block on others with Tikz?

Here is the diagram I am trying to make using tikz. Blocks A, B and C are inside a block (here, block with red background) and blocks E and F are inside another block. The two huge blocks (with red background) have labels on top (LabA and LabB). Moreover, I would like block E to be right and in the middle of the blocks A and B. And arrows going to block E should have some bending angle; so, not like in the one I have tried.
Here is my code.
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=black, thick, text width=2cm, minimum height=1cm, align=center]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\node[block] (a) {a};
\node[block, below=of a, yshift=0.7cm] (b) {b};
\node[block, below=of b, yshift=0.7cm] (c) {c};
\node[block, right=of c, xshift=0.7cm] (d) {d};
\node[block, right=of a, xshift=0.7cm, yshift=-0.4cm] (e) {e};
\draw [arrow] (a) -- (e);
\draw [arrow] (b) -- (e);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
How could I add a rectangle over some nodes and write a label on top of it.
How to have the arrows here with a certain angle of inclination (not straight), and also to have the E block in the middle and in right of the A and B blocks. I though I could get the arrows with \draw [arrow] (a) -|- (e);, but it does not work.
Thank you in advance
I gave it a try in the hope of getting the requirements right:
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=none, thick, text width=.4cm, minimum height=.5cm, align=center, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\Large
%red rectangles
\node (r1) [draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r2) [right=2cm of r1.center, anchor=center, draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r1Label)[above=0cm of r1] {\textbf{LabA}};
\node (r2Label)[above=0cm of r2]{\textbf{LabB}};
%nodes
\node[block, below=3mm of r1.north, anchor=north] (a) {\color{white}A};
\node[block, below=4mm of a] (b) {\color{white}B};
\node[block, below=4mm of b] (c) {\color{white}C};
\node[block, right=2cm of c.center, anchor=center] (d) {\color{white}D};
\node at ($(a.south)+(2,-.2)$) [block] (e) {\color{white}E};
%arrows
\draw [arrow, rounded corners=2] (a) -- ($(a)+(1,0)$) |- ($(e.west)+(0,.1)$);
\draw [arrow, rounded corners=2] (b) -- ($(b)+(1,0)$) |- ($(e.west)+(0,-.1)$);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
With this result:
Some explanations:
You can just draw rectangles in the back by defining them before the other nodes. There are more sophisticated ways using layers, but I think in this example it suffices.
I mostly used absolute distances like in the given example code. You may have to adjust... However, using these you can easily find out the middle between A and B (distance 4mm) to find the y-Position of E (a.south+ 2mm). Using ($(node1)+(node2)$) you can calculate node positions.
The -|- option you mentioned works in two steps. First draw -- to some anchor point (otherwise this is ambiguous), then |- to the target node.
The rounded corners option for draw takes the rounding radius as a parameter.

CircuiTikZ and FET drawing

Is there some simple way to avoid shorting the pins of a FET?
\documentclass{standalone}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0)
to[I,I=$I_s$] (0,2) % The current source
to[short] (2,2);
\draw (2,0)
to node[nigfete]{FET} (2,2) % The FET transistor
to[short] (2,0) to[short] (0,0);
\draw (2,2)
to[short] (4,2)
to[R=$R$] (4,0)
to[short] (2,0);
\draw (4,2);
\draw node[rground]{};
\end{circuitikz}
\end{document}
I am not sure to understand what you want to achieve, but
use short only if you need to add poles or labels, otherwise -- is easier to type;
use the anchors of the components.
tikz is automatically loaded by circuitikz, and that one has a mandatory argument (the voltage direction standard, look at the manual and at the wanings! ;-).
So a first change could be this:
\documentclass[border=4pt] {standalone}
\usepackage[RPvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[rground]{}
to[I,I=$I_s$] (0,2) -- (2,2)
node[nigfete, anchor=D](F){FET} % The FET transistor
(F.S) to[short, -*] (2,0) -- (0,0);
\draw (2,2) -- (4,2)
to[R=$R$] (4,0) -- (2,0);
\draw node[rground]{};
\end{circuitikz}
\end{document}
which leads to:
then, in my opinion, it would be better to use relative positioning to make the circuit relocatable.
If you need/want the FET centered in the branch it could be better to start with it or use the calc TikZ library (already loaded by circuitikz). In the following circuit all the movement are relative, so you can move it by just changing the first (0,0):
\documentclass[border=4pt] {standalone}
\usepackage[RPvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) node[rground](GND){} to[I,I=$I_s$] ++(0,2)
-- ++(2,0) coordinate(top)
-- ++(2,0) to[R=$R$] ++(0,-2)
-- (GND-|top) coordinate(bottom)
-- (GND)
($(top)!0.5!(bottom)$) node[nigfete](F){FET}
(F.D) -- (top) (F.S) -- (bottom);
\end{circuitikz}
\end{document}

How can I fix this error when using Tikz for Overleaf?

I'm trying to do a diagram with arrows. I have been able to produce the diagram but with no arrows using this code:
\begin{tikzpicture}
\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};
\draw (a) -- (z1);
\draw (a) -- (z2);
\draw (a) -- (z3);
\end{tikzpicture}
But I need the segments to be arrows and add tags to the segments but when I try this code:
\begin{tikzpicture}
\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};
\draw [->] (a) -- (z1) {$1/2$};
\draw [->] (a) -- (z2) {$1/4$};
\draw [->] (a) -- (z3) {$1/4$};
\end{tikzpicture}
I get an error in the first \draw line that says:
Argument of \language?#active#arg> has an extra }.
Runaway argument?
Missing \endcsname inserted.
And then in the \end{tikzpicture} line I get:
Extra }, or forgotten \endgroup.
Missing } inserted.
The complete code I'm using is this:
\documentclass[spanish]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % Required for custom headers
\usepackage{lastpage} % Required to determine the last page for the footer
\usepackage{extramarks} % Required for headers and footers
\usepackage[usenames,dvipsnames]{color} % Required for custom colors
\usepackage{graphicx} % Required to insert images
\usepackage{listings} % Required for insertion of code
\usepackage{courier} % Required for the courier font
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};
\draw [->] (a) -- (z1) node[midway,above] {$1/2$};
\draw [->] (a) -- (z2) node[midway,above] {$1/4$};
\draw [->] (a) -- (z3) node[midway,above] {$1/4$};
\end{tikzpicture}
\end{document}
There are a couple of problems:
the \draw command does not take a label like the \node command. If you want to add text to the arrow there are several possibilities, for example \draw [->] (a) -- (z1) node[midway,above] {$1/2$};
then you are also loading the spanish babel package. This introduces a couple of shorthands to write spanish characters which interfere with tikz. Either switch these shorthands off or load the tikz babel library
please don't load packages more than once
have a look at the nicefrac package to get nicer fractions
\documentclass[spanish]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
%\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % Required for custom headers
\usepackage{lastpage} % Required to determine the last page for the footer
\usepackage{extramarks} % Required for headers and footers
\usepackage[usenames,dvipsnames]{color} % Required for custom colors
\usepackage{graphicx} % Required to insert images
\usepackage{listings} % Required for insertion of code
\usepackage{courier} % Required for the courier font
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{natbib}
%\usepackage{graphicx}
%\usepackage{amsmath}
%\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{babel}
\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};
\draw [->] (a) -- (z1) node[midway,above] {$1/2$};
\draw [->] (a) -- (z2) node[midway,above] {$1/4$};
\draw [->] (a) -- (z3) node[midway,above] {$1/4$};
\end{tikzpicture}
\end{document}
Try edge command between the nodes
\begin{tikzpicture}
\node (a) at (0,0) {$a$};
\node (z1) at (3,2) {$z_1$};
\node (z2) at (3,0) {$z_2$};
\node (z3) at (3,-2) {$z_3$};
\draw [->] (a) edge (z1) (a) edge (z2) (a) edge (z3);
\end{tikzpicture}

How to add symbols on edges to say they are same length?

There are some edges having the same length. I want to add little symbol on it as in the picture:
How do I do? Thanks.
\begin{tikzpicture}
\coordinate (Base1) at (0,0);
\coordinate (Base2) at (4,0);
\coordinate (Base3) at (5,2);
\coordinate (TopPt) at (2,5);
\draw [draw=black, every edge/.append style={draw=black, dashed}]
(Base1) -- (Base2) --(Base3)
(Base3) edge (Base1);
\draw [draw=black, every edge/.append style={draw=black, dashed}]
(TopPt) -- (Base1)
(TopPt) -- (Base2)
(TopPt) -- (Base3);
\end{tikzpicture}
You'll need the tikz decoration library (both decorations and decorations.markings):
\begin{tikzpicture}
\coordinate (Base1) at (0,0);
\coordinate (Base2) at (4,0);
\coordinate (Base3) at (5,2);
\coordinate (TopPt) at (2,5);
\draw [draw, every edge/.append style={draw, dashed}]
(Base1) -- (Base2) -- (Base3)
(Base3) edge (Base1);
\draw [draw]
(TopPt) -- (Base1)
(TopPt) -- (Base2)
(TopPt) -- (Base3);
\draw [draw,decoration={markings, mark=at position .5 with {\node[transform shape] {$\parallel$};}}]
(TopPt) edge[decorate] (Base1)
(TopPt) edge[decorate] (Base2)
(TopPt) edge[decorate] (Base3);
\end{tikzpicture}

How to change arrow tip in tikz

Is there a simple way to increase the size of an arrow tip using something like:
\tikzset{myptr/.style=->, ????}
without designing a new arrow style from scratch?
One solution, very quick, to just scale the arrow head is number %2 in the following:
\documentclass[multi=false,tikz,border=2mm]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}
%1
\draw [->,>=stealth] (0,.5) -- (2,.5);
%2
\draw [decoration={markings,mark=at position 1 with
{\arrow[scale=3,>=stealth]{>}}},postaction={decorate}] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}
This produces:
(sorry for excessive zoom).
Much more in the answers to this question and in this answer, that I used as a source.
Addendum
\tikzset approach. This code:
\documentclass[multi=false,tikz,border=2mm]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzset{myptr/.style={decoration={markings,mark=at position 1 with %
{\arrow[scale=3,>=stealth]{>}}},postaction={decorate}}}
%1
\draw [->,>=stealth] (0,.5) -- (2,.5);
%2
\draw [myptr] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}
produces the same output as the above one (source: PGF Manual, section 2.8).
Obviously you can use -Latex instead of stealth.
There is a new solution, see https://latexdraw.com/exploring-tikz-arrows/#t-1610685307397. It allows changing both the length and width of arrows:
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,arrows}
\begin{document}
\begin{tikzpicture}
\draw [-{Stealth[length=3mm, width=2mm]}] (0,0.5) -- (1,0.5);
\draw [-stealth] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}

Resources