9

I export a picture from GeoGebra and I scale it, for example

\begin{figure}[H]
\centering 

\resizebox{0.5\textwidth}{!}{%
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw(0.,0.) circle (1.cm);
\draw (0.,0.)-- (2.,2.);
\draw(3.,3.) circle (2.cm);
\draw [rotate around={0.:(2.,4.)}] (2.,4.) ellipse (2.5cm and 1.5cm);
\draw(-1.,2.) circle (1.cm);
\draw (-2,2.) node[anchor=east] {$e_1$};
\draw (-1,0.) node[anchor=north west] {$e_2$};
\draw (1.,1.) node[anchor=north west] {$e_3$};
\draw (-0.5,4.) node[anchor=east] {$e_4$};
\draw (3.,1.) node[anchor=north] {$e_5$};
\draw (0.,0.) node[anchor=north ] {$v_1$};
\draw (0.,4.) node[anchor=north ] {$v_2$};
\draw (2.,4.) node[anchor=north ] {$v_3$};
\draw (4.,4.) node[anchor=north ] {$v_4$};
\draw (2.,2.) node[anchor=north west ] {$v_5$};
\draw (4.,2.) node[anchor=north] {$v_6$};
\begin{scriptsize}
\draw [fill=black] (0.,0.) circle (1.5pt);
\draw [fill=black] (2.,4.) circle (1.5pt);
\draw [fill=black] (4.,4.) circle (1.5pt);
\draw [fill=black] (2.,2.) circle (1.5pt);
\draw [fill=black] (4.,2.) circle (1.5pt);
\draw [fill=black] (0.,4.) circle (1.5pt);
\end{scriptsize}
\end{tikzpicture}
}
\end{figure}

Then everything in figure is scaled including text.

But there is a problem, when I export another picture that has different size of previous one and using "resizebox" again. Then, the size of text is not equal to the old in previous figure.

\begin{figure}[H]
\centering
\resizebox{0.5\textwidth}{!}{%
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm][font=\normalsize]
\draw [rotate around={-27.087902355643216:(2.8573157200548693,-0.14756503735849646)}] (2.8573157200548693,-0.14756503735849646) ellipse (2.5481820433499047cm and 1.5397201856917841cm);
\draw [rotate around={34.683048757121114:(4.67999090913984,-0.5899302005094594)}] (4.67999090913984,-0.5899302005094594) ellipse (3.3609235422094357cm and 2.528507164935098cm);
\draw [rotate around={-27.087902355643266:(3.9876766057699897,1.195446721504902)}] (3.9876766057699897,1.195446721504902) ellipse (2.5481820433499047cm and 1.5397201856917841cm);
\draw [rotate around={34.683048757121:(2.040722758983297,1.599931430026935)}] (2.040722758983297,1.599931430026935) ellipse (3.3609235422094303cm and 2.528507164935095cm);
\draw (-0.3,4.12) node[anchor=north west] {$e_2$};
\draw (7.98,-0.32) node[anchor=north west] {$e_4$};
\draw (2.42,3.56) node[anchor=north west] {$e_3$};
\draw (-0.1,0.66) node[anchor=north west] {$e_1$};
\draw (4.30,0.08) node[anchor=north west] {$v_3$};
\draw (2.16,1.54) node[anchor=north west] {$v_1$};
\draw (2.36,-0.16) node[anchor=north west] {$v_2$};
\draw (4.30,1.78) node[anchor=north west] {$v_4$};
\begin{scriptsize}
\draw [fill=black] (2.24,1.3) circle (1.5pt);
\draw [fill=black] (4.30,-0.16) circle (1.5pt);
\draw [fill=black] (4.36,1.54) circle (1.5pt);
\draw [fill=black] (2.36,-0.4) circle (1.5pt);
\end{scriptsize}
\end{tikzpicture}
}
\end{figure}

Is there a way to make text size in two figure equal?

6

You should scale coordinates rather than the whole picture. However scaling at 50% will also require modifying the positions of some elements.

Example with the figure at normal size and scaled at 75%:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,arrows}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw(0.,0.) circle (1.cm);
\draw (0.,0.)-- (2.,2.);
\draw(3.,3.) circle (2.cm);
\draw [rotate around={0.:(2.,4.)}] (2.,4.) ellipse (2.5cm and 1.5cm);
\draw(-1.,2.) circle (1.cm);
\draw (-2,2.) node[anchor=east] {$e_1$};
\draw (-1,0.) node[anchor=north west] {$e_2$};
\draw (1.,1.) node[anchor=north west] {$e_3$};
\draw (-0.5,4.) node[anchor=east] {$e_4$};
\draw (3.,1.) node[anchor=north] {$e_5$};
\draw (0.,0.) node[anchor=north ] {$v_1$};
\draw (0.,4.) node[anchor=north ] {$v_2$};
\draw (2.,4.) node[anchor=north ] {$v_3$};
\draw (4.,4.) node[anchor=north ] {$v_4$};
\draw (2.,2.) node[anchor=north west ] {$v_5$};
\draw (4.,2.) node[anchor=north] {$v_6$};
\draw [fill=black] (0.,0.) circle (1.5pt);
\draw [fill=black] (2.,4.) circle (1.5pt);
\draw [fill=black] (4.,4.) circle (1.5pt);
\draw [fill=black] (2.,2.) circle (1.5pt);
\draw [fill=black] (4.,2.) circle (1.5pt);
\draw [fill=black] (0.,4.) circle (1.5pt);
\end{tikzpicture}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm,scale=0.75]
\draw(0.,0.) circle (1.cm);
\draw (0.,0.)-- (2.,2.);
\draw(3.,3.) circle (2.cm);
\draw [rotate around={0.:(2.,4.)}] (2.,4.) ellipse (2.5cm and 1.5cm);
\draw(-1.,2.) circle (1.cm);
\draw (-2,2.) node[anchor=east] {$e_1$};
\draw (-1,0.) node[anchor=north west] {$e_2$};
\draw (1.,1.) node[anchor=north west] {$e_3$};
\draw (-0.5,4.) node[anchor=east] {$e_4$};
\draw (3.,1.) node[anchor=north] {$e_5$};
\draw (0.,0.) node[anchor=north ] {$v_1$};
\draw (0.,4.) node[anchor=north ] {$v_2$};
\draw (2.,4.) node[anchor=north ] {$v_3$};
\draw (4.,4.) node[anchor=north ] {$v_4$};
\draw (2.,2.) node[anchor=north west ] {$v_5$};
\draw (4.,2.) node[anchor=north] {$v_6$};
\draw [fill=black] (0.,0.) circle (1.5pt);
\draw [fill=black] (2.,4.) circle (1.5pt);
\draw [fill=black] (4.,4.) circle (1.5pt);
\draw [fill=black] (2.,2.) circle (1.5pt);
\draw [fill=black] (4.,2.) circle (1.5pt);
\draw [fill=black] (0.,4.) circle (1.5pt);
\end{tikzpicture}

\end{document}

enter image description here

I removed the useless (and wrong) scriptsize declaration.

  • Thank for your good idea. So, I must scale all picture with the same scale to preserve the same text size, right? – user75073 May 30 '15 at 11:33
  • Oh, I see the text size in all picture are same. Thank again. – user75073 May 30 '15 at 11:44
4

\resizebox, \scalebox, option transform canvas={scale=...} are all scaling everything including line width and the text. Thus you need rather option scale, which only scales the coordinates.

However, the calculation is much more difficult, because then the drawing consists of scalable and non-scalable elements. Because of the latter, the drawing will usually have a minimum size, which also the smallest scaling factor cannot reduce. Also the node positioning might need manual adjustments, especially if the scale factor is much different from the unscaled case.

The following example uses an approximation method to get the desired width. Environment imgresize is defined. It first catches the contents via package environ. Then the caught drawing is set in its natural size with scale=1. The difference to the desired width and a new scaling factor is calculated. If the width difference is larger than a threshold, a new scaling factor is calculated and the drawing with the new scaling factor measured. This is repeated until the width difference does not exceed the threshold.

Example file with threshold of 0.1 pt:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{environ}

\makeatletter
\newdimen\imgresize@width
\newdimen\imgresize@threshold
\setlength{\imgresize@threshold}{.1pt}

\NewEnviron{imgresize}[1]{%
  \pgfmathsetlength\imgresize@width{#1}%
  \edef\BODY{% remove spaces at the begin and end
    \ignorespaces\unexpanded\expandafter{\BODY}\unskip
  }%
  \typeout{}%
  %
  \def\imgresize@scale{1}%
  \tikzset{every picture/.style={scale=\imgresize@scale}}%
  \count@=\@ne
  \typeout{* imgresize: try=\the\count@, scale=\imgresize@scale}%
  \sbox0{\BODY}%
  \pgfmathsetlengthmacro\imgresize@diff{abs(\imgresize@width-\wd0)}%
  \@whiledim\imgresize@diff>\imgresize@threshold\do{%
    \let\imgresize@oldscale\imgresize@scale
    \pgfmathsetmacro\imgresize@scale{%
      \imgresize@width*\imgresize@scale/\the\wd0
    }%
    \ifx\imgresize@scale\imgresize@oldscale
      \PackageWarning{imgresize}{%
        Scale factor does not change anymore,\MessageBreak
        width difference is \imgresize@diff,\MessageBreak
        larger than threshold \the\imgresize@threshold
      }%
      \def\imgresize@diff{0pt}% abort loop
    \else
      \advance\count@\@ne
      \typeout{* imgresize: try=\the\count@, scale=\imgresize@scale}%
      \sbox0{\BODY}%
      \pgfmathsetlengthmacro\imgresize@diff{abs(\imgresize@width-\wd0)}%
    \fi
  }%
  \usebox{0}%
}
\makeatother

\begin{document}
\begin{figure}
\centering
\begin{imgresize}{0.49\textwidth}
  \begin{tikzpicture}[
    line cap=round,
    line join=round,
    >=triangle 45,
    x=1.0cm,
    y=1.0cm,
  ]
    \draw(0.,0.) circle (1.cm);
    \draw (0.,0.)-- (2.,2.);
    \draw(3.,3.) circle (2.cm);
    \draw [rotate around={0.:(2.,4.)}] (2.,4.) ellipse (2.5cm and 1.5cm);
    \draw(-1.,2.) circle (1.cm);
    \draw (-2,2.) node[anchor=east] {$e_1$};
    \draw (-1,0.) node[anchor=north west] {$e_2$};
    \draw (1.,1.) node[anchor=north west] {$e_3$};
    \draw (-0.5,4.) node[anchor=east] {$e_4$};
    \draw (3.,1.) node[anchor=north] {$e_5$};
    \draw (0.,0.) node[anchor=north ] {$v_1$};
    \draw (0.,4.) node[anchor=north ] {$v_2$};
    \draw (2.,4.) node[anchor=north ] {$v_3$};
    \draw (4.,4.) node[anchor=north ] {$v_4$};
    \draw (2.,2.) node[anchor=north west ] {$v_5$};
    \draw (4.,2.) node[anchor=north] {$v_6$};
    \draw [fill=black] (0.,0.) circle (1.5pt);
    \draw [fill=black] (2.,4.) circle (1.5pt);
    \draw [fill=black] (4.,4.) circle (1.5pt);
    \draw [fill=black] (2.,2.) circle (1.5pt);
    \draw [fill=black] (4.,2.) circle (1.5pt);
    \draw [fill=black] (0.,4.) circle (1.5pt);
  \end{tikzpicture}
\end{imgresize}\hfill
\begin{imgresize}{.49\textwidth}
  \begin{tikzpicture}[
    line cap=round,
    line join=round,
    >=triangle 45,
    x=1.0cm,
    y=1.0cm,
  ][font=\normalsize]
    \draw [rotate
    around={-27.087902355643216:(2.8573157200548693,-0.14756503735849646)}]
    (2.8573157200548693,-0.14756503735849646) ellipse (2.5481820433499047cm and
    1.5397201856917841cm);
    \draw [rotate
    around={34.683048757121114:(4.67999090913984,-0.5899302005094594)}]
    (4.67999090913984,-0.5899302005094594) ellipse (3.3609235422094357cm and
    2.528507164935098cm);
    \draw [rotate
    around={-27.087902355643266:(3.9876766057699897,1.195446721504902)}]
    (3.9876766057699897,1.195446721504902) ellipse (2.5481820433499047cm and
    1.5397201856917841cm);
    \draw [rotate
    around={34.683048757121:(2.040722758983297,1.599931430026935)}]
    (2.040722758983297,1.599931430026935) ellipse (3.3609235422094303cm and
    2.528507164935095cm);
    \draw (-0.3,4.12) node[anchor=north west] {$e_2$};
    \draw (7.98,-0.32) node[anchor=north west] {$e_4$};
    \draw (2.42,3.56) node[anchor=north west] {$e_3$};
    \draw (-0.1,0.66) node[anchor=north west] {$e_1$};
    \draw (4.30,0.08) node[anchor=north west] {$v_3$};
    \draw (2.16,1.54) node[anchor=north west] {$v_1$};
    \draw (2.36,-0.16) node[anchor=north west] {$v_2$};
    \draw (4.30,1.78) node[anchor=north west] {$v_4$};
    \draw [fill=black] (2.24,1.3) circle (1.5pt);
    \draw [fill=black] (4.30,-0.16) circle (1.5pt);
    \draw [fill=black] (4.36,1.54) circle (1.5pt);
    \draw [fill=black] (2.36,-0.4) circle (1.5pt);
  \end{tikzpicture}
\end{imgresize}
\end{figure}
\end{document}

Result

The log output:

* imgresize: try=1, scale=1
* imgresize: try=2, scale=0.78491
* imgresize: try=3, scale=0.76906
* imgresize: try=4, scale=0.76756

* imgresize: try=1, scale=1
* imgresize: try=2, scale=0.5902
* imgresize: try=3, scale=0.56789
* imgresize: try=4, scale=0.56583

The final scaling factors after four tries for the two drawings are 0.76756 and 0.56583. The quite small number of the second drawing also shows, that the node positions are no longer optimal.

With minimized threshold

\setlength{\imgresize@threshold}{0pt}

the result is:

* imgresize: try=1, scale=1
* imgresize: try=2, scale=0.78491
* imgresize: try=3, scale=0.76906
* imgresize: try=4, scale=0.76756
* imgresize: try=5, scale=0.76743
* imgresize: try=6, scale=0.76741

Package imgresize Warning: Scale factor does not change anymore,
(imgresize)                width difference is 0.00093pt,
(imgresize)                larger than threshold 0.0pt on input line 83.


* imgresize: try=1, scale=1
* imgresize: try=2, scale=0.5902
* imgresize: try=3, scale=0.56789
* imgresize: try=4, scale=0.56583
* imgresize: try=5, scale=0.56563
* imgresize: try=6, scale=0.56561

Package imgresize Warning: Scale factor does not change anymore,
(imgresize)                width difference is 0.0007pt,
(imgresize)                larger than threshold 0.0pt on input line 121.

The differences are quite negligible and the warnings can be ignored.

Caveat:

Because of the minimum size of the drawing, the loop might be repeated forever. In theory, the minimum size could be calculated via a scaling factor of zero. But the drawing might malfunction very badly with division by zero errors, for example. The example checks in the loop, whether the new scale factor has changed and issues a warning, if the scale factor does not change, but the width difference is larger than the threshold.

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.