0

I am trying to add a caption to the following tikzpicture but its creating a huge space underneath. I'm not sure how to fix this. enter image description here

\documentclass[a4paper,12pt]{article} 
    \usepackage{tikz}
    \usetikzlibrary{angles, calc, intersections, positioning, quotes, backgrounds}
        \usepackage{pgfplots,caption}
        \pgfplotsset{compat=1.9}
        \begin{document}
\begin{center}
    \begin{tikzpicture}
        \begin{scope}
             \clip (-2,-3.5) rectangle (0,3.5);
             \draw (0,2) circle(1);
        \end{scope}
                \draw[->] (0,-1) -- (0,4);
            \draw[->] (-2,0) -- (2,0);`

            \node at (0,3)[right] (1){\footnotesize $a_{2}$}; 
            \node at (0,1)[right] (2){\footnotesize $a_{1}$}; 

            \node at (-1,3)[right] (3){\footnotesize $\gamma$}; 

            \filldraw[black] (0,1) circle (1pt);
            \filldraw[black] (0,3) circle (1pt);
    \end{tikzpicture}
    \captionof{figure}{Example}
\end{center}
\end{document}
0

1 Answer 1

1

You have

\clip (-2,-3.5) rectangle (0,3.5);

in your document, which, apart from clipping, adds a rectangle path that is taken into account in the bounding box computation. You can either make the rectangle smaller, e.g.

\clip (-2,-0) rectangle (0,3.1);

or just exclude the rectangle from the bounding box computation via overlay,

 \clip[overlay] (-2,-3.5) rectangle (0,3.5);

MWE (with unnecessary packages and libraries removed):

\documentclass[a4paper,12pt]{article} 
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{center}
\begin{tikzpicture}[node font=\footnotesize]
 \begin{scope}
 \clip[overlay] (-2,-3.5) rectangle (0,3.5);
 \draw (0,2) circle[radius=1];
 \end{scope}
 \draw[->] (0,-1) -- (0,4);
 \draw[->] (-2,0) -- (2,0);`

 \node at (0,3)[right] (1){$a_{2}$}; 
 \node at (0,1)[right] (2){$a_{1}$}; 

 \node at (-1,3)[right] (3){$\gamma$}; 

 \filldraw[black] (0,1) circle[radius=1pt];
 \filldraw[black] (0,3) circle[radius=1pt];
\end{tikzpicture}
\captionof{figure}{Example}
\end{center}
\end{document}

enter image description here

Needless to say that you could just draw an arc and abandon \clip to get the same result.

Your Answer

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