Tikzscale-不可缩放的图片

Tikzscale-不可缩放的图片

我想使用 tikzscale 包来缩放我的图片。我使用以下代码

\usepackage{graphicx}
\usepackage{ifthen}
\usepackage{tikz-cd}
\usepackage{tikz}
\usepackage{tikzscale}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings} 
\usetikzlibrary{arrows, arrows.meta}
\usetikzlibrary{matrix, arrows, decorations.pathmorphing}



%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[->-] or \draw[->-=6pt red 1]
%-------------------------------------------------------------------------------%
\tikzset{ ->-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow{stealth}}, }, 
        postaction={decorate}, }, 
    ->-/.default= {0.5 6pt black }}


%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[-<-] path; or \draw[-<-=6pt red 1] path;
%-------------------------------------------------------------------------------%
\tikzset{ -<-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow[>=stealth]{<}}, }, 
        postaction={decorate}, }, 
    -<-/.default= {0.5 6pt black }}


\begin{document}
    \begin{center}
    \includegraphics[width=0.5\textwidth]{Polygon1.tikz}
    \end{center}
\end{document}

不幸的是,这会产生错误“请求缩放不可缩放的图形”。我的图形由以下代码给出(必须保存为 Polygon1.tikz)

    \begin{tikzpicture}
%Polygon 21 Seiten
\node[fill=gray!10] (pol) [
  %draw,
  minimum size=0.6\textwidth,
  regular polygon, regular polygon sides=21,
  rotate=270,
  ]{};
\foreach \x/\y/\i in {1/2/1,5/6/2,9/10/3} %\alpha's
  \draw[black!10!red,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {3/4/1,7/8/2,11/12/3} %inverse \alpha's
   \draw[black!10!red,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {2/3/1,6/7/2,10/11/3} %\beta's
  \draw[black!10!blue,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {4/5/1,8/9/2,12/13/3} %inverse \beta's
   \draw[black!10!blue,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {13/14/1, 16/17/2,19/20/3} %\xi's
  \draw[black!40!green,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!40!green,midway]{$\xi_ {\i}$};
\foreach \x/\y/\i in {15/16/1,18/19/2,21/1/3} %inverse \xi's
   \draw[black!40!green,auto=right,-<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!40!green,midway]{$\xi_{\i}$};
\foreach \x/\y/\i in {14/15/1,17/18/2,20/21/3} %\rho's
  \draw[violet,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[violet,midway]{$\rho_{\i}$};
\end{tikzpicture}

我猜问题出在最小尺寸上。但我不知道如何不使用它。有什么想法吗?我不想缩放字体大小,这应该与图片周围的文本保持一致。这就是我想使用 tikzscale 的原因。

答案1

我从未使用过tikzscale,但总是可以缩放图片。您可以直接使用scale=0.5,当然您可能想要添加,transform shape因为整个图片都是一个节点。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations.markings} 



%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[->-] or \draw[->-=6pt red 1]
%-------------------------------------------------------------------------------%
\tikzset{ ->-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow{stealth}}, }, 
        postaction={decorate}, }, 
    ->-/.default= {0.5 6pt black }}


%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[-<-] path; or \draw[-<-=6pt red 1] path;
%-------------------------------------------------------------------------------%
\tikzset{ -<-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow[>=stealth]{<}}, }, 
        postaction={decorate}, }, 
    -<-/.default= {0.5 6pt black }}
\begin{document}
\begin{tikzpicture}[scale=0.5,transform shape]
%Polygon 21 Seiten
\node[fill=gray!10] (pol) [
  %draw,
  minimum size=0.6\textwidth,
  regular polygon, regular polygon sides=21,
  rotate=270,
  ]{};
\foreach \x/\y/\i in {1/2/1,5/6/2,9/10/3} %\alpha's
  \draw[black!10!red,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {3/4/1,7/8/2,11/12/3} %inverse \alpha's
   \draw[black!10!red,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {2/3/1,6/7/2,10/11/3} %\beta's
  \draw[black!10!blue,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {4/5/1,8/9/2,12/13/3} %inverse \beta's
   \draw[black!10!blue,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {13/14/1, 16/17/2,19/20/3} %\xi's
  \draw[black!40!green,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!40!green,midway]{$\xi_ {\i}$};
\foreach \x/\y/\i in {15/16/1,18/19/2,21/1/3} %inverse \xi's
   \draw[black!40!green,auto=right,-<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!40!green,midway]{$\xi_{\i}$};
\foreach \x/\y/\i in {14/15/1,17/18/2,20/21/3} %\rho's
  \draw[violet,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[violet,midway]{$\rho_{\i}$};
\end{tikzpicture}
\end{document}

如果要保持字体大小不变,可以调整多边形的大小。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations.markings} 



%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[->-] or \draw[->-=6pt red 1]
%-------------------------------------------------------------------------------%
\tikzset{ ->-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow{stealth}}, }, 
        postaction={decorate}, }, 
    ->-/.default= {0.5 6pt black }}


%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[-<-] path; or \draw[-<-=6pt red 1] path;
%-------------------------------------------------------------------------------%
\tikzset{ -<-/.style args={#1 #2 #3}{
        decoration={markings,mark= at position 0.5 with {\arrow[>=stealth]{<}}, }, 
        postaction={decorate}, }, 
    -<-/.default= {0.5 6pt black }}
\begin{document}
\begin{tikzpicture}
%Polygon 21 Seiten
\node[fill=gray!10] (pol) [
  %draw,
  minimum size=0.4\textwidth,
  regular polygon, regular polygon sides=21,
  rotate=270,
  ]{};
\foreach \x/\y/\i in {1/2/1,5/6/2,9/10/3} %\alpha's
  \draw[black!10!red,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {3/4/1,7/8/2,11/12/3} %inverse \alpha's
   \draw[black!10!red,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!red,midway]{$\alpha_{\i}$};
\foreach \x/\y/\i in {2/3/1,6/7/2,10/11/3} %\beta's
  \draw[black!10!blue,auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {4/5/1,8/9/2,12/13/3} %inverse \beta's
   \draw[black!10!blue,auto=right, -<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!10!blue,midway]{$\beta_{\i}$};
\foreach \x/\y/\i in {13/14/1, 16/17/2,19/20/3} %\xi's
  \draw[black!40!green,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[black!40!green,midway]{$\xi_ {\i}$};
\foreach \x/\y/\i in {15/16/1,18/19/2,21/1/3} %inverse \xi's
   \draw[black!40!green,auto=right,-<-]
     (pol.corner \x)--(pol.corner \y)
     node[black!40!green,midway]{$\xi_{\i}$};
\foreach \x/\y/\i in {14/15/1,17/18/2,20/21/3} %\rho's
  \draw[violet,auto=right,->-]
    (pol.corner \x)--(pol.corner \y)
      node[violet,midway]{$\rho_{\i}$};
\end{tikzpicture}
\end{document}

相关内容