0

Let's suppose the following situation (wich is the simplest I could think): a circle intersepts two different points of a line and we call these points C and D.

\documentclass[a4paper, 10pt]{article}
    \usepackage{tikz}
    \usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
    
    \begin{figure}[h!]
    \centering
        \begin{tikzpicture}
        \coordinate (A) at (-2,0);
        \coordinate (B) at (2,0);
        \coordinate (P) at (0,1);
        \draw [name path=line] (A)--(B);
        \draw [name path=circle] (P) circle (1.5cm);
        \path [name intersections ={of=line and circle,name=N,total=\t}];
        \node at (N-1)[below left]{C};
        \node at (N-2)[below right]{D};
        \end{tikzpicture}
    \end{figure}

Which lead us to the meaning of the figure.
\end{document}

enter image description here

My situation actually uses the through library, would be, in the example, something like giving a point (C or D) of the line and drawing a circle from P passing through this point. I don't really know if it does change the problem. The thing is: what if I just wanted the coordinates? Instead of using \draw, I'd use \path (or \node at (?) [circle through (...)];) and whatever commands to simply get the coordinates. In the example, I just switched \draw [name path=circle] (P) circle (1.5cm); to \path [name path=circle] (P) circle (1.5cm);

\documentclass[a4paper, 10pt]{article}
    \usepackage{tikz}
    \usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
    
    \begin{figure}[h!]
    \centering
        \begin{tikzpicture}
        \coordinate (A) at (-2,0);
        \coordinate (B) at (2,0);
        \coordinate (P) at (0,1);
        \draw [name path=line] (A)--(B);
        \path [name path=circle] (P) circle (1.5cm);
        \path [name intersections ={of=line and circle,name=N,total=\t}];
        \node at (N-1)[below left]{C};
        \node at (N-2)[below right]{D};
        \end{tikzpicture}
    \end{figure}

Which lead us to the meaning of the figure.
\end{document}

enter image description here

This huge blank space. How to get rid of it in order to get something like this:

enter image description here

By the way, for the last image I just typed C and D coordinates as approximations of the actual X coordinate for both of them.

1
  • Even if paths are not drawn, they still contribute to the bounding box. So you may want to use \path [name path=circle,overlay] (P) circle (1.5cm); in the second example, as well as \path[overlay] (0,1) coordinate (P);.
    – user228539
    Nov 16 '20 at 16:26
2

Even if paths are not drawn, they still contribute to the bounding box. So you may want to use the overlay key on auxiliary paths and coordinates. overlay makes sure that they do not contribute to the bounding box.

\documentclass[a4paper, 10pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
    
    \begin{figure}[h!]
    \centering
        \begin{tikzpicture}
        \path (-2,0) coordinate (A) (2,0) coordinate (B);
        \path[overlay] (0,1) coordinate (P);
        \draw [name path=line] (A)--(B);
        \path[overlay,name path=circle] (P) circle[radius=1.5cm];
        \path [name intersections ={of=line and circle,name=N}];
        \node at (N-1)[below left]{C};
        \node at (N-2)[below right]{D};
        \end{tikzpicture}
    \end{figure}

Which lead us to the meaning of the figure.
\end{document}

enter image description here

1

Another approach is to reset the bounding box and recreate it to include only specific nodes and scopes (using local bounding boxes).

\documentclass[a4paper, 10pt]{article}
    \usepackage{tikz}
    \usetikzlibrary{intersections,fit}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
    
    \begin{figure}[h!]
    \centering
        \begin{tikzpicture}
        \coordinate (A) at (-2,0);
        \coordinate (B) at (2,0);
        \coordinate (P) at (0,1);
        \draw [name path=line] (A)--(B);
        \path [name path=circle] (P) circle (1.5cm);
        \path [name intersections ={of=line and circle,name=N,total=\t}];
        \node (C) at (N-1)[below left]{C};
        \node (D) at (N-2)[below right]{D};
        \pgfresetboundingbox
        \node[fit=(A) (B) (C) (D)] {};
        \draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
        \end{tikzpicture}
    \end{figure}

Which lead us to the meaning of the figure.
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.