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 .
Related
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}
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}
I am new to Tikz and can not figure out why relarivly small tikzpictures expand thier width to the entire page ones.
Since I want my texts floating around such figures, it would be very usefull to know how to prevent them from expanding.
Here are code and pictures of my problem and as you can see it's not caused by to long captions, what was my first idea.
\section{demo}
\begin{figure}[h]
\tdplotsetmaincoords{60}{25}
\begin{tikzpicture}[tdplot_main_coords, scale=1]
\coordinate (o) at (0,0,0);
\coordinate (x) at (4,0,0);
\coordinate (y) at (0,0,4);
\coordinate (z) at (0,-4,0);
\node[above] at (x) {x};
\node[above] at (y) {y};
\node[above] at (z) {z};
\draw[red, -latex] (o) -- (x);
\draw[green, -latex] (o) -- (y);
\draw[blue, -latex] (o) -- (z);
\end{tikzpicture}
\caption{far to long caption for this kind of sensless figure created just for demonstrationg tikzpicture expand their width}
\end{figure}
\begin{figure}[h]
%[... same code as above ...]
\end{figure}
Do you guys have any suggestions to fit the tikzpicture bounds to the contents?
Thanks.
This is the default behavior. You can use the wrapfigure package to wrap text around a tikz figure:
\begin{wrapfigure}{r}{0.4\textwidth}
\tdplotsetmaincoords{60}{25}
\begin{tikzpicture}[tdplot_main_coords, scale=1]
...
\end{tikzpicture}
\caption{far to long caption for this kind of sensless figure created just for demonstrationg tikzpicture expand their width}
\end{wrapfigure}
In \begin{wrapfigure}{r}{0.4\textwidth}, the first argument is the position (r for right), the second argument is the size of the wrapfigure (here 40% of the page width fits the tikz figure).
I reduced my problem to the following simple example:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\frametitle{Example:}
\pause
\begin{tikzpicture}
\draw (0,0) rectangle (2,2);
\pause
\draw (1,1) circle [radius=1cm];
\end{tikzpicture}
\pause
Comment
\end{frame}
\end{document}
I would like to see the following behaviour:
Slide 1: Title "Example:"
Slide 2: previous contents and a rectangle
Slide 3: previous contents and a circle
Slide 4: previous contents and "Comment"
However I get:
Slide 1: Title "Example:"
Slide 2: previous contents, a rectangle and "Comment"
Slide 3: Title "Example:", a rectangle and a circle
Slide 4: previous contents and "Comment"
In other words, "Comment" appears in slide 2 (it should not) and in slide 4 (where it should). I know that there are issues with using \pause within tikzpicture environment and I tried other solutions like \only but it did not work. Finally I split my picture in two halves and used \vspace{-20.5mm} between them but that's a very poor solutions for a more complicated picture which would require very fine adjustments. Any other suggestions?
To choose the order of appearance of the pauses, you can use \onslide:
\begin{frame}
\frametitle{Example:}
\onslide<2->{
\begin{tikzpicture}
\draw (0,0) rectangle (2,2);
\onslide<3->{
\draw (1,1) circle [radius=1cm];
}
\end{tikzpicture}
}
\onslide<4->{
Comment
}
\end{frame}
See this example.
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.