Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Problem

I use a tool which generates TikZ-Code (R with tikzDevice, to be precise). But the generated picture has a wide white border which I want to remove. When I manually (or with a script) remove every \path[clip] and \path[use as bounding box], I get the expected result.

Is there a way to disable these two commands in TikZ, so that everything happens automatically?

I have read TikZ: Cropping the Bounding Box, where the answere was that TikZ could not know which paths to remove – in my case, TikZ could know.

Code

% 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}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Are you sure tikzDevice doesn't have an option to turn that off? TikZ calculates the bounding box automatically so this is kind of an artifact left from rather old PSTricks habits. And I think you would be better off having the data from R and using directly pgfplots instead of this.

Here is a very stupid way of doing it. It should only be used on these type of pictures but not others. One can also take the long way and consider if \path is given an option that starts with u or c. Again I would skip this way of operating completely and use 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}
share|improve this answer
    
Thank you, this is what I was looking for. Another solution I came up with lately, which is propably more "clean": Using arara for my LaTeX-workflow, I have writte a rule fixtikzdevice which removes the unneeded lines. So I have lmkclean>knitr>fixtikzdevice>pdflatex>... –  ralfix May 15 '13 at 17:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.