5

Let's suppose a drawing that uses a simple decoration (for illustration, let's say a simple spring):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=2] %scale in question
\draw[decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}] 
    (0,0) -- (2,0);
\end{tikzpicture}   
\end{document}

The output without scale:

without scale

And with scale:

with scale

So yes, the line is scaled, but the decoration is not. Is there an option to scale a decoration?

The spring decoration is a minimal example, more interesting would be fancier decorations like tangent (from here):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}[
tangent/.style={
    decoration={
        markings,% switch on markings
        mark=
        at position #1
        with
        {
            \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
            \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
            \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
        }
    },
    postaction=decorate
},
use tangent/.style={
    shift=(tangent point-#1),
    x=(tangent unit vector-#1),
    y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\draw [tangent=0.7] (0,0) to [out=90,in=100] (2,0);
\draw [blue, thick, use tangent, ->] (0,0) -- (-1,0);
\end{tikzpicture}
\end{document}

creates the following output:

tangent without scale

Adding scale=2:

tangent with scale

Is there an option to avoid that?

2
  • In this particular case, you can wrap the whole tikzpicture in a \scalebox{2}{...}. But I don't know if that suffices for your general need. Sep 18, 2017 at 17:13
  • 1
    No because that also scales text, which would be bad.
    – jaytar
    Sep 18, 2017 at 17:17

1 Answer 1

4

Just the easy way:

You can define a \myscale parameter and use it inside your figures:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,shapes}

\begin{document}

\def\myscale{2}

\begin{tikzpicture}[scale=\myscale,
tangent/.style={
    decoration={
        markings,% switch on markings
        mark=
        at position #1
        with
        {
            \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
            \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
            \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
        }
    },
    postaction=decorate
},
use tangent/.style={
    shift=(tangent point-#1),
    x=(tangent unit vector-#1),
    y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\draw [tangent=0.7] (0,0) to [out=90,in=100] (2,0);
\draw [blue, thick, use tangent, ->] (0,0) -- ({-1*\myscale},0);
\end{tikzpicture}

\begin{tikzpicture}[scale=\myscale] %scale in question
\draw[decorate,decoration={zigzag,
                                    pre length={0.3*\myscale cm},
                                    post length={0.3*\myscale cm},
                                    segment length={6*\myscale},
                                    amplitude={6*\myscale}}] 
    (0,0) -- (2,0);
\end{tikzpicture} 

\end{document}

Output:

enter image description here

Rescale it to check results.

3
  • You have to avoid shift options to be sure it works ok... xshift and yshift is ok but shift will not be rescaled as you expect.
    – koleygr
    Sep 18, 2017 at 17:46
  • Good idea for a first solution.
    – jaytar
    Sep 18, 2017 at 17:52
  • You can expand it ... (At least I use it like this)... You can add an if statement (with as many branches as you think you need) to check scaling and select \myfont (for \normalsize, \large etc) or \myfontsize(for \fontsize{10}{12}\selectfont etc -With anyfontsize you can also just multiply font and bazelineskip by \myscale or use it as you wish-) parameter. This way the text gets rescaled too in your preferred way. I think you will not find another so easy solution because many options in tikz rescale and other doesn't... This means other way for any other shape options...
    – koleygr
    Sep 18, 2017 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .