# Tikzpictures inside newcommand. Text below tikzpicture. Space between side by side tikzpictures. Overlapping drawings. (Not fully answered)

I'm learning tikz and I wanted to do something like this:

Example Image

I have managed to get to:

My try (Edit: Grammar, Clarify, Solved questions)


From now on, "Figure 1" will reference the left tikzpicture of My try; "Figure 2" will do it with the right one.

I have the following problems I can't solve:

1. Space between both figures (Solved by AndréC)

Figure 1 sticks to left margin (as wanted) not as Figure 2 does (with right margin). Tikzpictures are put side by side by default but I can't get the Figure 2 closer to the Figure 1.

2. Title of tikzpicture (Solved by AndréC)


2.1 Float/Int numbers in title

On another note, I don't know why the first title is "Figure (-3.0, 4) radius=2", instead of "Figure (-3.0,4.0) radius=2.0", as it occurs in the second title. (I'd like "Figure (-3, 4) radius=2" in Figure 1 and "Figure (-4, -2) radius=1.5" in Figure 2).

3. Text after tikzpicture (Solved by AndréC)

I don't know what is happening to "Segment length", the corresponding text to Figure 1 appears in the middle, and the corresponding to Figure 2 appears in the left.

4. Overlap question

IMPORTANT DETAIL, In figure 1 of Example Image, the red segment has its first node in the centre of the circumference, but it's overlapped by it. In the same way, triangle overlaps the circumference, and the segment overlaps the triangle (in the area not covered by the circumference). I don't know if something like this could be done in LaTeX, I'm just curious about it. (Here's the question) I wonder (for two differents drawings in the same tikzpicture, for instance, segment and circumference) if the only way to make one thing overlaps the other is increasing the opacity of the one you want to be above.

My code (MWE) is:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,math}
\usetikzlibrary{shapes.misc}
\usepackage{pgfplots}

\usepackage{vmargin}
\setmargins{2.5cm}
{1.5cm}
{15.5cm}
{23.42cm}
{10pt}
{1cm}
{0pt}
{2cm}

\begin{document}

\newcommand{\learningtikz}[3]{
\tikzmath{
\mya = #1;
\myb = #2;
\myr = #3;
\d = veclen(\mya - 0, \myb - (-1));
}
\begin{tikzpicture}
\begin{axis}[
axis lines* = middle,
axis equal,
xmin = -5, xmax= 8, ymin= -5, ymax = 7,
xtick = \empty, ytick = \empty,
extra x ticks={\mya, 2},
extra y ticks={\myb, -1}
]
\filldraw [red] (axis cs:\mya,\myb) circle (0.1);
\filldraw [red] (axis cs:0,-1) circle (0.1);
\draw[dashed, red] (\mya, \myb) -- (0, -1);
\filldraw [dashed, green, fill opacity=0.1] (axis cs:\mya,\myb) circle(\myr);
\filldraw [blue, fill opacity=0.2](-2.5,1) -- (6,0) -- (\mya+1,\myb+1) -- (-2.5,1);
\node [label={(a,b)}] at (\mya, \myb) {};
\node [label={Figure (\mya,\myb) radius=\myr}] at (0,-5) {};
\end{axis}
\end{tikzpicture}
\medskip
Segment length is \d
}

\learningtikz{-3}{4}{2}
\learningtikz{-4}{-2}{1.5}

\end{document}


The figures are from TeX's point of view large boxes and the text itself is composed of boxes. These boxes are placed side by side and so the figure on the right is placed after the text boxes that separate them. To bring the figures closer together, I simply included the text in the figures with the operation node.

The code is commented with %<--

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,math}
\usetikzlibrary{shapes.misc}
\usepackage{pgfplots}

\usepackage{vmargin}
\setmargins{2.5cm}
{1.5cm}
{15.5cm}
{23.42cm}
{10pt}
{1cm}
{0pt}
{2cm}

\begin{document}

\newcommand{\learningtikz}[3]{
\tikzmath{
\mya = #1;
\myb = #2;
\myr = #3;
\d = veclen(\mya - 0, \myb - (-1));
}
\begin{tikzpicture}
\begin{axis}[
axis lines* = middle,
axis equal,
xmin = -5, xmax= 8, ymin= -5, ymax = 7,
xtick = \empty, ytick = \empty,
extra x ticks={\mya, 2},
extra y ticks={\myb, -1}
]
\filldraw [red] (axis cs:\mya,\myb) circle (0.1);
\filldraw [red] (axis cs:0,-1) circle (0.1);
\draw[dashed, red] (\mya, \myb) -- (0, -1);
\filldraw [dashed, green, fill opacity=0.1] (axis cs:\mya,\myb) circle(\myr);
\filldraw [blue, fill opacity=0.2](-2.5,1) -- (6,0) -- (\mya+1,\myb+1) -- (-2.5,1);
\node [label={(a,b)}] at (\mya, \myb) {};
\node [label={Figure (\mya,\myb) radius=\myr}] at (0,-5) {};
\end{axis}

\node [below,yshift=-3pt,thick,label={[below,draw,inner sep=3pt,thick,font=\bf]:Figure (\mya,\myb) radius=\myr}] at (current bounding box.south) {};%<-- name of the figure below the current bounding box
\node[below] at (current bounding box.south){ Segment length is \d};%<-- positioning of the text under the figure (below the current bounding box which is now bigger
\end{tikzpicture}
%\medskip
}

\learningtikz{-3}{4}{2}
\learningtikz{-4}{-2}{1.5}

\end{document}