2

My code goes like this:

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=.8]
    
    %*****************************************************************************************************************************
    % C Í R C U L O S

    \tkzDefPoint(0,0){A}
    \tkzDefPoint(6,0){B}
    
    \tkzLabelPoints(A,B)
    \tkzDrawPoints(A,B)
    
    \tkzDrawCircle[R](A,3cm)
    \tkzDrawCircle[R](B,1.5cm)

    \path[name path = R1] (0,0) circle (3cm);
    \path[name path = r1] (6,0) circle (1.5cm);
    
    \path[name path = R2] (0,0) --++ (-3,-3);
    \path[name path = r2] (6,0) --++ (-1.5,-1.5);

    %*****************************************************************************************************************************
    % R A D I O S
    
    \path[name intersections={of=R1 and R2, by={R}}];
    \path[name intersections={of=r1 and r2, by={r}}];
    
    \draw[->] (0,0) -- (R) node[midway,sloped,above] {$R$};
    \draw[->] (6,0) -- (r) node[midway,sloped,above] {$r$};
    
    %*****************************************************************************************************************************
    % D I S T A N C I A S
    
    \draw[<->] (0,4) -- (6,4) node[midway,fill=white] {$D$};

    \tkzExtSimilitudeCenter(A,3)(B,1.5)
    \tkzGetPoint{I}

    \tkzDefTangent[from with R=I](A,3cm)
    \tkzGetPoints{C}{D}
    \tkzDefTangent[from with R=I](B,1.5cm)
    \tkzGetPoints{C'}{D'}

    \draw (C) -- (C');
    \draw (D) -- (D');

    \end{tikzpicture}
    \caption{}
    \label{fig:massmann}
\end{figure}

My tikzpicture was too wide, so I scaled it down to make it fit inside the document. However, what I get is this:

enter image description here

The figure name is the reference to know where the center is. As you can see, I'm using \centering, but my figure is not centered. I tried \begin{center}\end{center}, but it didn't work either. What can I do to center my figure?

Thanks in advance!

4
  • 2
    Add \draw[red] (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle; at the end of your tikzpicture and you will see that the whole box will indeed be centered on the page. The bounding box is just extending further to the right than expected which makes your image appear off center.
    – leandriis
    Oct 6, 2020 at 21:39
  • 2
    To overcome this, you could use pgfinterruptboundingbox (as also suggested for example here: tex.stackexchange.com/a/130209/134144 and here: tex.stackexchange.com/a/304905/134144) and place it around \tkzExtSimilitudeCenter as in \begin{pgfinterruptboundingbox} \tkzExtSimilitudeCenter(A,3)(B,1.5) \end{pgfinterruptboundingbox}.
    – leandriis
    Oct 6, 2020 at 21:45
  • You're right and made me open my eyes! It's because I'm using \tkzExtSimilitudeCenter(A,3)(B,1.5). That's an invisible point to the right of the little circle. I must either move the picture manually or figure out how to get rid of that invisible point. Thank you so much! Oct 6, 2020 at 21:47
  • 2
    Just "hide" it from the bounding box calculation using the pgfinterruptboundingbox environment and you can keep this invisible point just like it is.
    – leandriis
    Oct 6, 2020 at 21:49

2 Answers 2

2

Adding

\draw[red] (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle; 

into your tikzpicture environment reveals that the bounding box of the picture (red) is extends further to the right than the visible parts of the image, thus leaving the impression that the image is off center, while it actually is centered with respect to the textwidth (blue):

enter image description here

This is caused by \tkzExtSimilitudeCenter(A,3)(B,1.5) which adds an invisible point right of the smaller circle.

To overcome this issue while keeping the image code (almost) the same, you can use the pgfinterruptboundingbox environment around the above mentioned command. This "hides" the invisible point from the bounding box calculation and results in the following output:

enter image description here

Full minimal working example:

\documentclass{article}
\usepackage{tkz-euclide}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}[scale=0.8]
    
    %*****************************************************************************************************************************
    % C Í R C U L O S

    \tkzDefPoint(0,0){A}
    \tkzDefPoint(6,0){B}
    
    \tkzLabelPoints(A,B)
    \tkzDrawPoints(A,B)
    
    \tkzDrawCircle[R](A,3cm)
    \tkzDrawCircle[R](B,1.5cm)

    \path[name path = R1] (0,0) circle (3cm);
    \path[name path = r1] (6,0) circle (1.5cm);
    
    \path[name path = R2] (0,0) --++ (-3,-3);
    \path[name path = r2] (6,0) --++ (-1.5,-1.5);

    %*****************************************************************************************************************************
    % R A D I O S
    
    \path[name intersections={of=R1 and R2, by={R}}];
    \path[name intersections={of=r1 and r2, by={r}}];
    
    \draw[->] (0,0) -- (R) node[midway,sloped,above] {$R$};
    \draw[->] (6,0) -- (r) node[midway,sloped,above] {$r$};
    
    %*****************************************************************************************************************************
    % D I S T A N C I A S
    
    \draw[<->] (0,4) -- (6,4) node[midway,fill=white] {$D$};
 




    \begin{pgfinterruptboundingbox}
           \tkzExtSimilitudeCenter(A,3)(B,1.5)
    \end{pgfinterruptboundingbox}
        \tkzGetPoint{I}
        \tkzDefTangent[from with R=I](A,3cm)
    \tkzGetPoints{C}{D}
    \tkzDefTangent[from with R=I](B,1.5cm)
    \tkzGetPoints{C'}{D'}

    \draw (C) -- (C');
    \draw (D) -- (D');
  
    \end{tikzpicture}
    \caption{}
    \label{fig:massmann}
\end{figure}


\end{document}
1

For fun, there's no problem making this figure with pstricks, and more specifically with pst-eucl, which defines commands to determine the common tangents of two circles:

 \documentclass{article}
 \usepackage{pst-eucl}

 \begin{document}

    \begin{figure}
    \centering
    \fbox{\begin{pspicture}(-3,-3)(7.5,4.1)
    \psset{arrowinset =0.12, dimen=inner}
    \pstGeonode[PosAngle=-60](0,0){A}(6,0){B}
    \pcline[offset=4cm]{<->}(A)(B)\ncput*{$D$}
    \pnodes(3;-135){R}(1.5;225){r}
    \AplusB(B)(r){r}
    \pstCircleOA{A}{R}\pstCircleOA{B}{r}
    \pstCircleExternalCommonTangent[PointSymbol=none, PointName=none, dimen=outer]{A}{R}{B}{r}{T1}{T2}{t1}{t2}
    \pcline[offsetA=1pt, offsetB=1.5pt](T1)(t1)\pcline[offsetA=-1pt, offsetB=-1.5pt](T2)(t2)
    \psset{arrows=->,nrot=:D, labelsep=2pt}
    \ncline{A}{R}\nbput{$R$}%
    \ncline{B}{r}\nbput[nrot=:D]{$r$}%
    \end{pspicture}}
    \caption{A centred caption}
    \end{figure}

 \end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .