3

I have two Tikz block code one after the other in my document in an enumerated list, Why does the following code scale the two Tikz figure differently? I am using the tkz-euclide package.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{tkz-euclide}
\usetkzobj{all}


\begin{document}

Find the area of the triangle:
\vspace{-1em}
\begin{center}
\resizebox{2.5in}{!}{
\begin{tikzpicture}
\coordinate (Q) at (0,0);
\coordinate (A) at ($(Q)+(40:5)$);
\coordinate (P) at ($(Q)+(150:4)$);
\draw (A) -- (Q) -- (P) -- cycle;
\tkzLabelPoint[below](Q){$Q$};
\tkzLabelPoint[right](A){$A$};
\tkzLabelPoint[left](P){$P$};
\path (A) -- node [midway,above] {$11$} (P);
\path (A) -- node [midway,below right] {$9$} (Q);
\path (P) -- node [midway,below left] {6} (Q);
\end{tikzpicture}}
\end{center}

The diagram below is the plan of a field. Find the area of the field.
\vspace{-1em}
\begin{center}
\resizebox{2.5in}{!}{
\begin{tikzpicture}
\coordinate (P) at (0,0);
\coordinate (S) at ($(P)+(-20:2)$);
\coordinate (Q) at ($(P)+(110:2)$);
\coordinate (R) at ($(P)+(45:2.5)$);
\draw (P) -- (Q) -- (R) -- (S) -- cycle;
\draw[dashed] (P) -- (R);
\tkzLabelPoint[left](Q){$Q$};
\tkzLabelPoint[left](P){$P$};
\tkzLabelPoint[right](S){$S$};
\tkzLabelPoint[right](R){$R$};
\path (P) -- node [midway,sloped,above] {$650$} (R);

\tkzLabelAngle[pos = 0.35](P,Q,R){$56^\circ$};
\tkzMarkAngle[size=0.65cm,](P,Q,R);
\tkzLabelAngle[pos = 0.35](S,P,R){$44^\circ$};
\tkzMarkAngle[size=0.65cm,](S,P,R);
\tkzLabelAngle[pos = 0.35](R,P,Q){$83^\circ$};
\tkzMarkAngle[size=0.65cm,](R,P,Q);
\tkzLabelAngle[pos = 0.35](P,R,S){$65^\circ$};
\tkzMarkAngle[size=0.65cm,](P,R,S);
\end{tikzpicture}}
\end{center}

\end{document}

enter image description here

3
  • At a glance, the \resizebox command scales each tikz picture to be 2.5in wide. Have you tried removing this command? – Andrew Kepert Dec 7 '15 at 6:05
  • 1
    Use scale instead, as specifying width/height is not a good idea. To quote this answer: "It does not make sense to specify the height/width of a tikzpicture, but does make sense to be able to specify the height/width of a pgfplots graph. With a tikzpicture only the scale option makes sense." – jak123 Dec 7 '15 at 6:27
  • Jak123, Isn't scaling bad for Tikz pictures, because it doesn't scale the text? What would be a good way to make all the picture the same size? – Ashish Dec 7 '15 at 14:50
7

That's because your original drawings (before scaling) were one much bigger and one much smaller than your desired size. You should try something like the scale option or the x=legth,y=length, which does not mess with the text.

(p.s. i'm not familiar with tkzMarkAngle but it sounds somehow wrong to specify size in cm instead of the figure units)

  \documentclass{article}
  \usepackage{pgfplots}
  \usepackage{tikz}
  \usetikzlibrary{calc}
  \usetikzlibrary{backgrounds}
  \usetikzlibrary{shapes.geometric}
  \usepackage{tkz-euclide}
  \usetkzobj{all}


  \begin{document}

    Find the area of the triangle:
    \vspace{-1em}
    \begin{center}
      %\resizebox{2.5in}{!}{
        \begin{tikzpicture}[scale=0.8]
          \coordinate (Q) at (0,0);
          \coordinate (A) at ($(Q)+(40:5)$);
          \coordinate (P) at ($(Q)+(150:4)$);
          \draw (A) -- (Q) -- (P) -- cycle;
          \tkzLabelPoint[below](Q){$Q$};
          \tkzLabelPoint[right](A){$A$};
          \tkzLabelPoint[left](P){$P$};
          \path (A) -- node [midway,above] {$11$} (P);
          \path (A) -- node [midway,below right] {$9$} (Q);
          \path (P) -- node [midway,below left] {6} (Q);
        \end{tikzpicture}%}
    \end{center}

    The diagram below is the plan of a field. Find the area of the field.
    \vspace{-1em}
    \begin{center}
      %\resizebox{2.5in}{!}{
        \begin{tikzpicture}[scale=1.8]
          \coordinate (P) at (0,0);
          \coordinate (S) at ($(P)+(-20:2)$);
          \coordinate (Q) at ($(P)+(110:2)$);
          \coordinate (R) at ($(P)+(45:2.5)$);
          \draw (P) -- (Q) -- (R) -- (S) -- cycle;
          \draw[dashed] (P) -- (R);
          \tkzLabelPoint[left](Q){$Q$};
          \tkzLabelPoint[left](P){$P$};
          \tkzLabelPoint[right](S){$S$};
          \tkzLabelPoint[right](R){$R$};
          \path (P) -- node [midway,sloped,above] {$650$} (R);

          \tkzLabelAngle[pos = 0.35](P,Q,R){$56^\circ$};
          %\tkzMarkAngle[size=0.65cm,](P,Q,R);
          \tkzMarkAngle[size=0.65](P,Q,R);
          \tkzLabelAngle[pos = 0.35](S,P,R){$44^\circ$};
          %\tkzMarkAngle[size=0.65cm,](S,P,R);
          \tkzMarkAngle[size=0.65](S,P,R);
          \tkzLabelAngle[pos = 0.35](R,P,Q){$83^\circ$};
          %\tkzMarkAngle[size=0.65cm,](R,P,Q);
          \tkzMarkAngle[size=0.65](R,P,Q);
          \tkzLabelAngle[pos = 0.35](P,R,S){$65^\circ$};
          %\tkzMarkAngle[size=0.65cm,](P,R,S);
          \tkzMarkAngle[size=0.65](P,R,S);
        \end{tikzpicture}%}
    \end{center}

  \end{document}

enter image description here

3
  • Davide, Thanks for your solution. I appreciate the explanation.!!! – Ashish Dec 7 '15 at 14:24
  • Davide, is there a trick to figuring out the scaling for each picture so that all your image sizes are the same without trial and error? Or is there a better option than scaling? According to jak123 above, scaling is the best option. – Ashish Dec 7 '15 at 14:32
  • nothing that I can think of right now... besides maybe considering the distances you use in your picture (4 and 5 in the first, 2 and 2,5 in the second). there could be a convoluted way of drawing first, then resizing, then adding an overlay with text - but i wouldn't know how to do that right now, I would have to check the manual and invest some time - which unfortunately I'm rather scarce of now =( – Davide Dec 8 '15 at 8:17
5

Firstly \resizeboxis a bad idea because you scale all objects (points, lines and fonts). Davide answer is correct you need to use scale optionfrom tikZ.

I put my code because tkz-euclide has a special syntax without ; and some commands can be simplify. You don't need to load Tikzbecause pgfplots and Tkz-Euclide use TikZ If the big part of your code use TikZwhy use tkz-euclide. It's a lot of code useless. Then when you use tkz-euclide, TikZ is always behind so when you don't know how do something you can can use Tikz but It's preferable to avoid the mixing. I use mark=none because angles are not equal.

I compile the code with the new version of tkz-euclide is here

 \documentclass{article}
  \usepackage{tkz-euclide}

\begin{document}

  Find the area of the triangle:

\begin{tikzpicture}[x=.8cm,y=.8cm]
  \tkzDefPoint(0,0){Q}
  \tkzDefShiftPoint[Q](40:5){A}  
  \tkzDefShiftPoint[Q](150:4){P} 
    \tkzDrawPolygon(A,P,Q)
  \tkzLabelPoint[below](Q){$Q$}
  \tkzLabelPoint[right](A){$A$}
  \tkzLabelPoint[left](P){$P$}
    \tkzLabelSegment[swap](A,P){$11$}
    \tkzLabelSegment[](A,Q){$9$}
    \tkzLabelSegment[](Q,P){$6$}
\end{tikzpicture}

 The diagram below is the plan of a field. Find the area of the field.

\begin{tikzpicture}[scale=1.8]
  \tkzDefPoint(0,0){P}
  \tkzDefShiftPoint[P](-20:2){S}  
  \tkzDefShiftPoint[P](110:2){Q} 
    \tkzDefShiftPoint[P](45:2.5){R} 
    \tkzDrawPolygon(P,...,S)
  \tkzDrawSegment[dashed](P,R)
  \tkzLabelPoint[left](Q){$Q$}
  \tkzLabelPoint[left](P){$P$}
  \tkzLabelPoint[right](S){$S$}
  \tkzLabelPoint[right](R){$R$}
  \tkzLabelSegment[sloped](P,R){$650$}
  \tkzLabelAngle[pos = 0.35](P,Q,R){$56^\circ$}
  \tkzLabelAngle[pos = 0.35](S,P,R){$44^\circ$}
  \tkzLabelAngle[pos = 0.35](R,P,Q){$83^\circ$}
  \tkzLabelAngle[pos = 0.35](P,R,S){$65^\circ$}
  \tkzMarkAngles[mark=none,size=0.65](P,R,S R,P,Q S,P,R P,Q,R)
\end{tikzpicture}

\end{document}

enter image description here

4
  • 1
    When we can expect tkz-euclide Version 2.55c on CTAN? With existed CTAN version I receive error \tkzDrawPolygon is unknow – Zarko Jan 9 '20 at 7:12
  • I think Sunday ... With the old version you need to place usetkzobj{all} in the preamble. With the new version i decide to load all the objects except protractor and show. Now the bounding box is controlled and generally you don't need to clip – Alain Matthes Jan 9 '20 at 10:43
  • @Zarko I ask in few minutes a new question about scaling because I discover yesterday a problem with my example of reference – Alain Matthes Jan 9 '20 at 10:46
  • unfortunately \usetkzobj{all´} cause new errors >(Runaway argument ... ! Paragraph ended before pgffor@@dotscharcheck was complete ). I need to wait for new version on CTAN :-). About scaling: this is about my knowledge ... :-( – Zarko Jan 9 '20 at 14:47

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.