2

I feel like this should be really simple, but I cannot figure out how to do it.

I want to scale a tikz figure entirely, paths and text.

I tried both of these, but neither causes the font to scale.

\begin{tikzpicture}[scale=0.5]   
\begin{tikzpicture}[scale=0.5,transform shape]

In my use case it is important that all ratios are preserved for any scale, and readability at small scales is not important, so I understand that this is not the usual need case. I need to be able to optically shrink or grow the figure without distorting it in any way.

Here is an example of a not optically shrunk image.

\documentclass[fontsize=12pt]{article}

\RequirePackage{graphicx}

\RequirePackage{tikz}                   %used for diagrams
    \usetikzlibrary{math,arrows,automata,positioning,calc,decorations.footprints,decorations.fractals,decorations.markings,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.text}
\begin{document}


\begin{tikzpicture}[scale=1,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            transform={scale=1},
            raise=1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=1}
        },
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            transform={scale=1},
            raise=1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=1}
        },
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}
\end{document}

enter image description here

  • You may read off the transformation matrix entries, compute the Jacobian, and insert the appropriate scale factor automatically. See tex.stackexchange.com/a/515305/194703 for the details. – user194703 Nov 11 '19 at 0:58
  • Is the text in a rectangle or other shape box--scaling the rectangle would then scale the text also--you may like to look at this post of mine--scaling did effect the text also tex.stackexchange.com/q/513891/197451 – js bibra Nov 11 '19 at 0:59
  • @Schrödinger'scat I do not understand you at all. Just the word jacobian makes me think this is the wrong thing. I just want to zoom the picture? – Bob Nov 11 '19 at 1:33
  • @Bob I spell this out in an explicit answer. Maybe I misunderstand the question, but in the answer the relation between the text and the circle is the same. If you want to rescale the line widths, too, have a look at tex.stackexchange.com/a/515305/194703. – user194703 Nov 11 '19 at 1:57
  • Take a look at tex.stackexchange.com/q/26846/86 – Andrew Stacey Nov 11 '19 at 7:07
1

You can determine the scale factor by computing the Jacobian of the transformation matrix. This has been used in various earlier answers like this one, this one, this one and this one. In order to avoid bad kerning, you need to add text effects={text along path}, drop the transform={scale=1}, key and also scale the raise.

\documentclass[fontsize=12pt]{article}

% \RequirePackage{graphicx} <- gets loaded by TikZ

\RequirePackage{tikz}                   %used for diagrams
%    \usetikzlibrary{math,arrows,automata,positioning,calc,decorations.footprints,decorations.fractals,decorations.markings,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.text}
\usetikzlibrary{decorations.text} %<- for this example we need only this libary
\begin{document}
\tikzset{get scale/.code={\pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
\pgfmathsetmacro{#1}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}%
}}

\begin{tikzpicture}[scale=1,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            /tikz/get scale=\myscale,
            raise=\myscale*1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=\myscale}
        },text effects={text along path},
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5,transform shape]
    \draw [
        postaction={decorate},
        decoration={
            /tikz/get scale=\myscale,
            raise=\myscale*1.5ex,
            text effects along path,
            text align=center,
            reverse path,
            text={Blue is a pretty color},
            text effects/.cd,
                characters={text along path,scale=\myscale}
        },text effects={text along path},
        rotate=-90
    ] (0,0) circle (2);
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Maybe we are not on the same page, as the results you show here are also not optically scaled copies; you can see this in the bad kerning in the text of the second figure. What I need is the equivalent of, while printing, to pick a scale percentage. – Bob Nov 11 '19 at 2:13
  • Ok I think I see what you are trying to do. You are trying to scale every piece independently, but why not just scale the whole figure at the end? – Bob Nov 11 '19 at 2:18
  • @Bob I thought that the question was "tikz scale everything: paths and text", and what this answer attempts to do is to scale the text according to the transformation of the tikzpicture. The kerning is indeed not optimal, it seems that one of the transformations is unnecessary, but this does not fix the kerning. – user194703 Nov 11 '19 at 2:25
  • By "everything: paths and text" I meant that by default the scale=0.5 command only scales paths and not text! And searching around you find a lot of people trying to do the exact opposite thing as me, where their font size is critical and they want it to stay matching the doccument while they scale the paths. I do not actually have a document to match; I need the whole figure, characters and all, to scale together. Im sorry for the confusion. To reiterate, the end goal I want to accomplish could be done by printing the first figure to a pdf, then using includegraphics[scale=0.5]{mypdf} – Bob Nov 11 '19 at 2:33
  • @Bob Yes, you can just scale the pdf. But what is your question then? What precisely do you want to achieve? – user194703 Nov 11 '19 at 3:27

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.