Increase spacing between itemize 'items' to avoid splitting pages - latex

I'm currently working on some homework for my Theory of Computation course; right now I am creating state diagrams in LaTeX with the TikZ library (in Overleaf). We have a template file where problems are listed in an itemize block and I am inserting tikzpicture blocks to create the state diagrams in each of the item blocks.
\begin{itemize}
\item[a.] $\{w~|~w$ begins with a $\input{1}$ and ends with a $\input{0} \}$
\begin{figure}[ht]
\begin{tikzpicture}
\node[state, initial] (q0) {$q_0$};
\node[state, right of=q0] (q1) {$q_1$};
\node[state, below of=q1] (qR) {$q_R$};
\node[state, accepting, right of=q1] (q2) {$q_2$};
\draw (q0) edge[bend right, below] node{0} (qR)
(qR) edge[loop below] node{0,1} (qR)
(q0) edge[above] node{1} (q1)
(q1) edge[loop above] node{1} (q1)
(q1) edge[bend left, above] node{0} (q2)
(q2) edge[bend left, below] node{1} (q1)
(q2) edge[loop right] node{0} (q2);
\end{tikzpicture}
\end{figure}
... Cut some code out here to save space
\item[d.] The empty set
\begin{figure}[ht]
\begin{tikzpicture}
\node[state, initial] (q) {$q$};
\draw (q) edge[loop right, above] node{0,1} (q);
\end{tikzpicture}
\end{figure}
\end{itemize}
The thing that is bothering me, and I know it's not a huge deal and I'm just being anal, is that it comes out looking like this when compiled:
Is there a way I could change this code so that both the problem statement and my solution diagram will fit on the same page of the pdf? It really bothers me to look at it and I run into stuff like this a lot working with LaTeX. Thanks!

A \vbox might do what you want:
\item \vbox{
% the contents you want to enclose on the same page
}

Related

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}

Prevent expanding tikz picture to wrap text around

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).

How to draw nodes with "stubs" in 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.

Modular arithmetic on node names in TikZ?

Say I want to construct a circulant graph in TikZ, with a variable number of nodes, labelled v0, v1, ..., v_n-1 for some n of my choice (say, 5).
I'd like to be able to use the \foreach command in TikZ to iteratively (1) define the nodes, and (2) connect the nodes. I'd like to be able to connect v_i to v_(i+1) and v_i to v_{i+2}, say.
\foreach \i in {0, ..., 4}
{\path (\i*72:3) node (v\i) {};}
constructs the nodes perfectly. But then when I want to draw some lines,
\foreach \i \in {0, ..., 3}
{ \draw (v\i) -- (v{\i+1}); } ????
doesn't work. Nor does
\foreach \i / \j in {0/1, ..., 3/4}
{ \draw (v\i) -- (v{\j}); }
I get an error "no such shape v0" or something like that.
I know this must be totally easy to do, but I can't figure out how. Any suggestions?
As a followup, it would be nice to be able to connect v_i and v_{i+4} or something, with a single \foreach command, and have TikZ/pgf do the modular arithmetic for me without having to worry about spilling over.
This worked for me:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,fit,arrows,positioning}
\tikzstyle{vertex} = [circle, draw, thick, text centered]
\tikzstyle{edge} = [draw, thick,->]
\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \x in {0,...,6}
\node[vertex] (\x) at (\x*360/7:3) {v\x};
\foreach \x/\y in {0/1,1/2,2/3,3/4,4/5,5/6,6/0}
\draw[edge] (\x) to (\y);
\end{tikzpicture}
\end{document}
The syntax {0/1,...,5/6} did not work for me. But I admit, I spent a bit of time trying to find a good solution, and I'm still not totally satisfied.
Another solution, achieved editing the code by Steve Tjoa:
\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[thick]
\foreach \x in {0,...,4}{%
\node [circle, draw] at (\x*72:3) {$v_{\x}$};
\draw [->] (\x*72+10:3) arc (\x*72+10:\x*72+62:3);
}
\end{tikzpicture}
\end{document}

Resources