8

I'm having some difficulty at scaling a TikZ draw inside a matrix:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[scale=.5]
    \matrix [yshift=2cm]{
       \draw (0,0)--(0.2,1)--(1,1.2)--(1.2,0)--(0,0);&
       \node{Some text that should not be scaled};\\
    };

    \draw (0,0)--(0.2,1)--(1,1.2)--(1.2,0)--(0,0);
    \end{tikzpicture}

 \end{document}

enter image description here

As you can see the same picture is scaled outside the matrix but not inside. I can't use the scalebox or resizebox methods because there is some text in my original picture that should not be scaled, as it happens by default when you scale via the TikZ own option.

So, why the draw does not scale inside the matrix? Is there some way I can make it scale without scaling the text too?

2
  • Did you try putting scale as an option for matrix too?
    – JLDiaz
    Dec 12, 2013 at 19:46
  • @JLDiaz tried now, doesn't work.
    – d-cmst
    Dec 12, 2013 at 19:49

2 Answers 2

9

This is one of those grey areas about cell picture issues. One not-super-clean solution is to set the transformation yourself.

\documentclass[margin=5pt,tikz]{standalone}
\begin{document}

    \begin{tikzpicture}[scale=.5]
    \pgfgettransform\mytrafo
    \matrix [yshift=2cm,execute at begin cell=\pgfsettransform\mytrafo]{
       \draw (0,0)--(0.2cm,1cm)--(1cm,1.2cm)--(1.2cm,0)--cycle;&
       \node{Some text that should not be scaled};\\
    };

    \draw (0,0)--(0.2,1)--(1,1.2)--(1.2,0)--(0,0);
    \end{tikzpicture}

 \end{document}

enter image description here

1
  • 1
    Great! Can't wait to mix up \pgfsettransform and \pgfgettransform as I just did while testing with my real picture :D
    – d-cmst
    Dec 12, 2013 at 20:08
1

As an alternative to using \pgfgettransform and pgfsettransform as suggested in the accepted answer, you can also explicitly transform every cell of the table as follows:

\matrix [yshift=2cm, every cell/.style={scale=0.5}]{
   \draw (0,0)--(0.2cm,1cm)--(1cm,1.2cm)--(1.2cm,0)--cycle;&
   \node{Some text that should not be scaled};\\
};
1

You must log in to answer this question.

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