在 TikZ 中禁用“剪辑”和“用作边界框”

在 TikZ 中禁用“剪辑”和“用作边界框”

问题

我使用生成 TikZ-Code 的工具(准确地说是带有 tikzDevice 的 R)。但生成的图片有一个宽白边,我想删除它。当我手动(或使用脚本)删除每个\path[clip]和时\path[use as bounding box],我得到了预期的结果。

有没有办法在 TikZ 中禁用这两个命令,以便一切都自动发生?

我读过了TikZ:裁剪边界框,答案是 TikZ 不知道要删除哪些路径——就我而言,TikZ 知道。

代码

% Created by tikzDevice version 0.6.2-92-0ad2792 on 2013-04-28 13:20:49
% !TEX encoding = UTF-8 Unicode
\begin{tikzpicture}[x=1pt,y=1pt]
\definecolor[named]{fillColor}{rgb}{1.00,1.00,0.00}
\path[use as bounding box] (0,0) rectangle (361.35,361.35);% DISABLE THIS LINE
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (361.35,361.35);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (195.07, 18.72) {$n\cdot\lambda\cdot d$};
\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 12.96,187.87) {$x_n$};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (361.35,361.35);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 60.03, 73.44) -- (307.81, 73.44);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 60.03, 73.44) -- ( 60.03, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (101.33, 73.44) -- (101.33, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (142.62, 73.44) -- (142.62, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (183.92, 73.44) -- (183.92, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (225.22, 73.44) -- (225.22, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (266.51, 73.44) -- (266.51, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (307.81, 73.44) -- (307.81, 66.24);
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 60.03, 47.52) {1e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (101.33, 47.52) {2e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (142.62, 47.52) {3e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (183.92, 47.52) {4e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (225.22, 47.52) {5e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (266.51, 47.52) {6e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (307.81, 47.52) {7e-06};
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04, 90.96) -- ( 59.04,291.82);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04, 90.96) -- ( 51.84, 90.96);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,141.17) -- ( 51.84,141.17);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,191.39) -- ( 51.84,191.39);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,241.61) -- ( 51.84,241.61);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,291.82) -- ( 51.84,291.82);
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64, 86.80) {5};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,137.02) {10};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,187.23) {15};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,237.45) {20};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,287.67) {25};
\end{scope}
\begin{scope}
\path[clip] ( 59.04, 73.44) rectangle (331.11,302.31);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.47,0.00,0.05}
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 69.12, 81.92) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (119.50,121.09) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (169.88,169.29) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (220.27,210.47) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (270.65,250.65) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (321.03,293.83) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] ( 59.04, 72.98) -- (331.11,302.77);
\end{scope}
\end{tikzpicture}

答案1

你确定 tikzDevice 没有关闭该功能的选项吗?TikZ 会自动计算边界框,所以这有点像 PSTricks 的旧习惯留下的遗留产物。我认为你最好从 R 获取数据,然后直接使用 pgfplots,而不是使用这个。

这是一种非常愚蠢的做法。它只应该用于这些类型的图片,而不是其他图片。你也可以走一条很长的路,考虑一下 \path 是否给出了以u或开头的选项c。同样,我会完全跳过这种操作方式,并使用pgfplots

\documentclass[11pt]{standalone} 
\usepackage{tikz} 
\makeatletter
\tikzset{dangerous style/.code={
    \tikzoption{clip}[]{\pgf@relevantforpicturesizefalse}
    \tikzoption{use as bounding box}[]{\pgf@relevantforpicturesizefalse}
    }
}
\makeatother

\begin{document}

\begin{tikzpicture}[x=1pt,y=1pt,dangerous style]
\definecolor[named]{fillColor}{rgb}{1.00,1.00,0.00}
\path[use as bounding box] (0,0) rectangle (361.35,361.35);% DISABLE THIS LINE
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (361.35,361.35);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (195.07, 18.72) {$n\cdot\lambda\cdot d$};
\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 12.96,187.87) {$x_n$};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (361.35,361.35);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 60.03, 73.44) -- (307.81, 73.44);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 60.03, 73.44) -- ( 60.03, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (101.33, 73.44) -- (101.33, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (142.62, 73.44) -- (142.62, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (183.92, 73.44) -- (183.92, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (225.22, 73.44) -- (225.22, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (266.51, 73.44) -- (266.51, 66.24);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (307.81, 73.44) -- (307.81, 66.24);
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 60.03, 47.52) {1e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (101.33, 47.52) {2e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (142.62, 47.52) {3e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (183.92, 47.52) {4e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (225.22, 47.52) {5e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (266.51, 47.52) {6e-06};
\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (307.81, 47.52) {7e-06};
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04, 90.96) -- ( 59.04,291.82);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04, 90.96) -- ( 51.84, 90.96);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,141.17) -- ( 51.84,141.17);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,191.39) -- ( 51.84,191.39);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,241.61) -- ( 51.84,241.61);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 59.04,291.82) -- ( 51.84,291.82);
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64, 86.80) {5};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,137.02) {10};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,187.23) {15};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,237.45) {20};
\node[text=drawColor,anchor=base east,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 44.64,287.67) {25};
\end{scope}
\begin{scope}
\path[clip] ( 59.04, 73.44) rectangle (331.11,302.31);% DISABLE THIS LINE
\definecolor[named]{drawColor}{rgb}{0.47,0.00,0.05}
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 69.12, 81.92) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (119.50,121.09) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (169.88,169.29) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (220.27,210.47) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (270.65,250.65) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (321.03,293.83) circle (  2.70);
\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] ( 59.04, 72.98) -- (331.11,302.77);
\end{scope}
\end{tikzpicture}
\end{document}

相关内容