7

After adding the last line of code to my tikzpicture I have a large white space between the text and the picture. I don't know what causes the problem.

I've already looked at similar questions, but none of them is handling this problem. Thanks.

enter image description here

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}

some text
\begin{center}
\begin{tikzpicture}
\coordinate (M) at (0,0) ;
\coordinate (B) at (-5,1.3) ;
\coordinate (C) at (5,1.3) ;
\draw (B) -- (C) node[below] {$a$};
\coordinate (A) at (canvas polar cs:angle=10,radius=2cm);
\draw (M) circle (2cm);
\draw (A) -- (M) node[midway,sloped,fill=white] {$r$} ;
\tkzInterLC[R](B,C)(M,2cm) \tkzGetPoints{E}{D}  %without this line%
\tkzDrawPoints(A,D,E,M)  %without D,E,%
\tkzLabelPoints(A,D,E,M)  %without D,E,   >>> no problem at all%
\end{tikzpicture}
\end{center}

\end{document}
  • 2
    Have a look to the second bullet point of this answer tex.stackexchange.com/a/23335/31058 . It seems to work with your code around the line you pointed out as the "problem" line. – Ludovic C. Aug 26 '13 at 15:47
  • @LudovicC. Thanks it worked, but still it is a strange behavior for this command. – Arne Timperman Aug 26 '13 at 15:57
  • 2
    I guess that it needs to compute some hidden points to get the intersection between the line and the circle and these points are quite above the "printed" part, which has for consequence to add this big white space. But this is a guess, I do not have proof for it. – Ludovic C. Aug 26 '13 at 16:01
9

After looking at the code, I think I can explain why this happens.

During the calculation of the intersections of a line AB and a circle, tkz-euclide, defines a coordinate that lies on a line that is normal to AB and the same distance away from the centre of the circle as the length of AB.

This coordinate is included in the bounding box, causing the problem. If you reduce the length of your line AB, you'll see that the white space above the figure shrinks.

A simple fix, borrowing from the answer Ludovic found, is to add

\makeatletter
\def\tkz@Projection(#1,#2)(#3)#4{%
\begingroup 
  \pgfpointdiff{\pgfpointanchor{#1}{center}}%
               {\pgfpointanchor{#2}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%
  \begin{pgfinterruptboundingbox}
  \path[coordinate](#3)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \end{pgfinterruptboundingbox}
  \tkz@InterLL(#1,#2)(#3,tkz@point){#4}% définit tkzPointResult 
\endgroup
}
\makeatother

to the preamble, after \usepackage{tkz-euclide}. Complete code, and output below:

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\makeatletter
\def\tkz@Projection(#1,#2)(#3)#4{%
\begingroup 
  \pgfpointdiff{\pgfpointanchor{#1}{center}}%
               {\pgfpointanchor{#2}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%
  \begin{pgfinterruptboundingbox}
  \path[coordinate](#3)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \end{pgfinterruptboundingbox}
  \tkz@InterLL(#1,#2)(#3,tkz@point){#4}% définit tkzPointResult 
\endgroup
}
\makeatother
\usetkzobj{all}
\begin{document}

some text
\begin{center}
\begin{tikzpicture}
\coordinate (M) at (0,0) ;
\coordinate (B) at (-5,1.3) ;
\coordinate (C) at (5,1.3) ;
\draw (B) -- (C) node[below] {$a$};
\coordinate (A) at (canvas polar cs:angle=10,radius=2cm);
\tkzDrawCircle(M,A)
\draw (A) -- (M) node[midway,sloped,fill=white] {$r$};
\tkzInterLC(B,C)(M,A) \tkzGetPoints{E}{D};  
\tkzDrawPoints(A,D,E,M);  
\tkzLabelPoints(A,D,E,M); 

% the following draws the bounding box of the tikzpicture
\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

5

I found that several people got this "blank" stuff. Here is a simple solution: put the command

\pgfresetboundingbox

right after \tkzInterLC[R](B,C)(M,2cm) \tkzGetPoints{E}{D}. Thế reason is the command \tkzInterLC[R] make a new bounding box, namely the box surrounding the current picture. PS: pgfresetboundingbox is the most unclear command in TikZ. In some rare cases, it does not work as expected.

  • 3
    Welcome to TeX.SX! You can highlight code in your post using back-ticks. To highlight code-blocks, either indent them by four spaces or use the {} on the gui. – user30471 Oct 6 '17 at 20:57
  • Thanks Andrew! I got it! the above comment is my first one here – Black Mild Oct 8 '17 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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