![绘制曲线路径时边界框比预期的大](https://linux22.com/image/245572/%E7%BB%98%E5%88%B6%E6%9B%B2%E7%BA%BF%E8%B7%AF%E5%BE%84%E6%97%B6%E8%BE%B9%E7%95%8C%E6%A1%86%E6%AF%94%E9%A2%84%E6%9C%9F%E7%9A%84%E5%A4%A7.png)
我一直在为我的部门设计徽标,我有以下代码。问题是,每当我编译时,图表似乎都比实际徽标大。我不知道问题是什么。我知道我选择的数字不是最好的,但任何对此事的见解都将不胜感激。
\documentclass[letterpaper]{article}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
%\usepackage{amsmath,amssymb,units}
%\usepackage{enumitem,multicol}
\usepackage{tikz}
%\usetikzlibrary{arrows}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\path[draw=black,fill=white]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\lipsum[1-2]
\end{document}
参见下图:
答案1
更新 :在使用网格之前,可以使用它pdfcrop
来获取“真实”图片的尺寸。您需要使用\thispagestyle{empty}
并仅编译图片。您会得到一个 pdf 文件,然后pdfcrop
会得到一个新的 pdf 文件。在这个 pdf 中,您可以阅读/BBox [0 0 146.908 142.991]
(注意单位)。我们没有原点,但我们得到了尺寸。pdfcrop
还可以提供一个 pdf 文件,您可以将其包含在正确的边界框中。
手动:使用网格
\documentclass[letterpaper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\draw[help lines,step=8pt] (208,208) grid (400, 400);
\clip (208,208) rectangle (400, 400);
\path[draw=black]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\path[draw=black] (213,215) rectangle (398, 395);
\clip (213,215) rectangle (398, 395);
\path[draw=black]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\end{document}
答案2
正如 Peter Grill 的回答所示,边界框的大小不仅由路径点决定,还由控制点决定。为了减小边界框的大小,我们必须明确指定它。
手册指出:
PGF 相当擅长跟踪图片的大小并在主文档中为其保留适当的空间。但是,在某些情况下,您可能想说“不将此算作图片大小”或“图片实际上有点大”。为此,您可以使用选项用作边界框或命令
\useasboundingbox
,这只是的简写\path[use as bounding box]
。
特别是对于曲线:
... 曲线的控制点通常位于曲线的“外部”,导致边界框过大。在这种情况下,您应该使用该
[use as bounding box]
选项。
tikzpicture
作为一种快速解决方法,您可以在绘图之前在您的环境中添加类似以下内容:
\path[use as bounding box] (220, 200) rectangle (400, 400);
为了进行更精确的计算,请找到能够以足够精度定义徽标凸包的点,并使用多边形作为边界框 - 这样同样有效。
以下是快速修复的结果:
答案3
这不是答案,但我认为了解为什么会发生这种情况可能会很有用,正如@user946850指出的那样。我在代码中添加了以下内容以查看控制点的位置:
\foreach \x in {{(173.9885,538.4766)}, {(568.5860,261.2969)}, {(44.4337,252.9312)},
{(429.9845,542.5624)}, {(275.9689,41.4788)}, {(119.6549,497.6604)}, {(548.6203,196.3394)}, {(66.4622,188.6439)}, {(485.5930,503.5010)}, {(343.9169,42.5633)}} {
\node [fill=red,shape=circle] at \x {};
};
查看边界框的另一种方法是在图片末尾应用以下内容:
\draw [blue] (current bounding box.south west) rectangle (current bounding box.north east);
答案4
绘制前先剪裁图形
\documentclass[letterpaper]{article}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
%\usepackage{amsmath,amssymb,units}
%\usepackage{enumitem,multicol}
\usepackage{tikz}
%\usetikzlibrary{arrows}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1]
\clip[draw](305,305) circle (100);
\path[draw=red,fill=white]
(258.9527,290.5199) .. controls (173.9885,538.4766) and (568.5860,261.2969) ..
(306.5098,257.1141) .. controls (44.4337,252.9312) and (429.9845,542.5624) ..
(352.9767,292.0206) .. controls (275.9689,41.4788) and (119.6549,497.6604) ..
(334.1376,346.9999) .. controls (548.6203,196.3394) and (66.4622,188.6439) ..
(276.0276,346.0724) .. controls (485.5930,503.5010) and (343.9169,42.5633) ..
(258.9527,290.5199) -- cycle;
\end{tikzpicture}
\lipsum[1-2]
\end{document}