How to draw nodes with "stubs" in Latex? - latex

I'm trying to draw this in latex.
Anyone know how?

Use the calc-library and do the following:
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[draw=black, circle, fill=green] (A) at (0,0) {A};
\draw let \p1=(A) in (A) -- (\x1+40,\y1+10);
\end{tikzpicture}
\end{document}
Using the let-statement it allows you to specify a reference point (or even more) to use it's coordinates for further calculation.

Related

How to make a graphic where one image points to two other images with arrows in latex?

I want to create a graphic like the one in the attached image in latex, where each box represents an image (a graphic I want to insert). I also want to be able to write a word over the arrows that point from one image to another.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[>=latex,node distance=2em]
\node(a){\includegraphics[width=4cm]{example-image-a}};
\node[right=of a](b){\includegraphics[width=4cm]{example-image-b}};
\draw[->] (a) -- (b);
\end{tikzpicture}
\caption{Two graphics.}
\end{figure}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[>=latex,node distance=2em]
\node(a){\includegraphics[width=3cm]{example-image-a}};
\matrix[right=of a,row sep=2em] {
\node(b){\includegraphics[width=3cm]{example-image-b}};\\
\node(c){\includegraphics[width=3cm]{example-image-duck}};\\
};
\draw[->] (a) -- (b);
\draw[->] (a) -- (c);
\end{tikzpicture}
\caption{Three graphics.}
\end{figure}
\end{document}
visit: https://tex.stackexchange.com/questions/527216/diagrams-arrows

Generating random points then connecting points less than certain distance away

I currently have the code below which produces the later output. I would like to generate the 10 points randomly as I already am. But instead of having blue dashed lines connecting to the the location (0,0), I want them to connect to the other dots if the distance is less than 4cm away.
I attempted things such as storing the data into arrays but updating and accessing the values was not working. I attempted nested for loops but handling the seed became difficult. What is a good way to do this?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-2.5,-2.5) grid (2.5,2.5);
\pgfmathsetseed{2}
\foreach \x in {1,...,10}
{
\pgfmathrandominteger{\a}{-240}{240}
\pgfmathrandominteger{\b}{-240}{240}
\fill [color=red,anchor=center](\a*0.01,\b*0.01) circle (0.1);
% CHANGE HERE
\draw [color=blue,densely dotted] (\a*0.01,\b*0.01) -- (0.0,0.0);
};
\end{tikzpicture}
\end{document}
I seemed to have figured out a solution (not ideal but works for this case).
The key was to use the \pgfmathparse for performing the if statement to get a 0 or 1 to use in \ifnum.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-2.5,-2.5) grid (2.5,2.5);
\pgfmathsetseed{2}
\foreach \x in {1,...,10}
{
\pgfmathrandominteger{\a}{-240}{240}
\pgfmathrandominteger{\b}{-240}{240}
\fill [color=red,anchor=center](\a*0.01,\b*0.01) circle (0.1);
\pgfmathsetseed{2}
\foreach \y in {0,...,\x}
{
\pgfmathrandominteger{\c}{-240}{240}
\pgfmathrandominteger{\d}{-240}{240}
\tikzmath{\i=(\a*0.01-\c*0.01)^2;}
\tikzmath{\j=(\b*0.01-\d*0.01)^2;}
\tikzmath{\k=\i+\j;}
\pgfmathparse{\k < 4.0 ? 1 : 0}
\ifnum\pgfmathresult=1
\draw [color=blue,densely dotted] (\a*0.01,\b*0.01) -- (\c*0.01,\d*0.01);
\fi
};
};
\end{tikzpicture}
\end{document}

circuitikz - move current labels closer to current arrow

how can I move the current label closer to the current arrow. I.e. I want to move the i_1 closer to the arrow.
MWE:
\documentclass{standalone}
\usepackage[european,cuteinductors,fetbodydiode,straightvoltages]{circuitikz}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[scale=0.65, arrowmos]
\coordinate (zero) at (0,0);
\draw (zero) to[R,-*,R=$R_1$,i>_=$i_1$] ++(2.75,2);
\end{tikzpicture}
\end{figure}
\end{document}
I tried to put a \vspace in front of the label but it didn't work.
I propose two solutions here: the first one is using a fake label and then setting the label manually (with a lot of flexibility), or using the provided styling for labels. Details in comments; you need a quite recent circuitikz for using this solution (>=1.4.2).
\documentclass{standalone}
\usepackage[european,cuteinductors,fetbodydiode,straightvoltages]{circuitikz}
\begin{document}
\centering
\begin{tikzpicture}[scale=0.65, arrowmos]
\coordinate (zero) at (0,0);
% First option
% use a blank label for the current, and name the component
\draw (zero) to[R,-*,R=$R_1$,i>_=~,name=myI] ++(2.75,2);
% manually place the label where you like
% myIcurrent is the normal position where the blank label is set
\node[below=1mm, anchor=center, red] at (myIcurrent) {$i_1$};
% you can also use bipole current style to change inner sep;
\draw (2,0) to[bipole current style={inner sep=0pt}, R,-*,R=$R_1$,i>_=$i_1$] ++(2.75,2);
\end{tikzpicture}
\end{document}
See circuitikz manual, https://texdoc.org/serve/circuitikz/0#subsection.5.6 .

TikZ - An arc with an arrow

I am learning Tikz and hope somebody can help me achieve the following i.e. I want to draw a directed arc between objects in an equation. Below is a picture of what I am trying to achieve.
I have also attached the code I have used so far:
\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\begin{tikzpicture}
$(x+2)(x+3)$
\end{tikzpicture}
\end{document}
I also suspect that there is a way to specify a line or arc, between elements e.g. numbers and letters, without explicitly stating the coordinates. Is this the case? If it were, it would simplify the things I'm trying to achieve.
Any help would be very much appreciated.
The following solution draws an arc above the formula using arc; the actual angles and lengths may have to be adjusted. To get coordinates relative to the formula, the formula is wrapped into the node formula.
\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\begin{tikzpicture}
\node (formula) [] {$(x+2)(x+3)$};
\draw[-latex,red] ($(formula.north west)+(.4,0)$) arc
[
start angle=160,
end angle=20,
x radius=0.5cm,
y radius =0.5cm
] ;
\end{tikzpicture}
\end{document}
Output:
Another possibility with the tikzmark library:
\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\begin{equation}
(\tikzmarknode{a}{x}+2)(\tikzmarknode{b}{x}+3)
\end{equation}
\tikz[remember picture, overlay]{\draw[-latex,red] ([yshift=0.1em]a.north) to[bend left] ([yshift=0.1em]b.north);}
\end{document}

LaTeX - Simple Text over Image

I'm replicating an word documment and need to place some text over an image in the header, but i can't find a simple method to do that.
It's just some text centered over a retangular image, but the best anwser I've found, so far, for doing that is reading an 880 page manual for PFG package.
Is there anyway to do that with some simple package, like minipage?
One possible approach using tikz:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {\includegraphics[width=6cm]{example-image-duck}};
\node at (current bounding box.center) {Quack};
\end{tikzpicture}
\end{document}

Resources