我的代码如下:
\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}
我的 tikzpicture 太宽了,所以我缩小了它以使其适合文档。但是,我得到的是这样的:
图形名称是了解中心位置的参考。如您所见,我使用了 \centering,但我的图形未居中。我尝试了 \begin{center}\end{center},但也没有用。我该怎么做才能使我的图形居中?
提前致谢!
答案1
添加
\draw[red] (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
进入您的tikzpicture
环境会发现,图片的边界框(红色)比图像的可见部分更向右延伸,从而给人留下图像偏离中心的印象,而实际上它相对于文本宽度(蓝色)位于中心:
这是因为\tkzExtSimilitudeCenter(A,3)(B,1.5)
在小圆圈的右侧添加了一个不可见的点。
为了解决这个问题,同时保持图像代码(几乎)相同,您可以使用pgfinterruptboundingbox
上述命令周围的环境。这会将不可见点从边界框计算中“隐藏”,并产生以下输出:
完整最小工作示例:
\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}
答案2
为了好玩,使用 制作这个图形没有问题pstricks
,更具体地说,使用pst-eucl
,它定义了确定两个圆的共同切线的命令:
\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}