将独立的 tikzpicture 粘贴到文档中时,其一部分会被缩放

将独立的 tikzpicture 粘贴到文档中时,其一部分会被缩放

我创建了这个漂亮的多边形 在此处输入图片描述 使用以下代码

\documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings} 
\usetikzlibrary{arrows, arrows.meta}

%==========================  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 12 Seiten
    \node[fill=gray!10] (pol) [ 
    %draw, 
    minimum size=0.9\textwidth, regular polygon, regular polygon sides=12, rotate=195 ]{};
    \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/1/3} %inverse \beta's
    \draw[black!10!blue,auto=right,-<-]
    (pol.corner \x)--(pol.corner \y)
    node[black!10!blue,midway]{$\beta_{\i}$};

    %\xi's
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
    (0,-5.44) --(-2.21,-0.63) node[midway, left] {$\xi_1$} ;
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
    (0,-5.44) -- (0,-20pt) node[midway, left] {$\xi_2$};
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}] 
    (0,-5.44) -- (2.21,-0.63) node[midway, left] {$\xi_3$};

    % 3 Kreise mit Beschriftung
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (-2.5,0) circle (20pt)  ;
    \node[violet,above] at (-2.5,20pt) {$\rho_1$};
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (0,0) circle (20pt);
    \node[violet,above] at (0,20pt) {$\rho_2$};
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (2.5,0) circle (20pt);
    \node[violet,above] at (2.5,20pt) {$\rho_3$};

    \end{tikzpicture}

\end{document}

现在,我尝试将此代码复制并粘贴到我的论文中。这是一个最简单的例子

    \documentclass[oneside, a4paper,12pt]{article}

\usepackage{ifthen}
\usepackage{tikz-cd}
\usepackage{tikz}
\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}
        \begin{tikzpicture}
        %Polygon 12 Seiten
        \node[fill=gray!10] (pol) [ 
        %draw, 
        minimum size=0.9\textwidth, regular polygon, regular polygon sides=12, rotate=195 ]{};
        \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/1/3} %inverse \beta's
        \draw[black!10!blue,auto=right,-<-]
        (pol.corner \x)--(pol.corner \y)
        node[black!10!blue,midway]{$\beta_{\i}$};

        %\xi's
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
        (0,-5.44) --(-2.21,-0.63) node[midway, left] {$\xi_1$} ;
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
        (0,-5.44) -- (0,-20pt) node[midway, left] {$\xi_2$};
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}] 
        (0,-5.44) -- (2.21,-0.63) node[midway, left] {$\xi_3$};

        % 3 Kreise mit Beschriftung
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (-2.5,0) circle (20pt)  ;
        \node[violet,above] at (-2.5,20pt) {$\rho_1$};
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (0,0) circle (20pt);
        \node[violet,above] at (0,20pt) {$\rho_2$};
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (2.5,0) circle (20pt);
        \node[violet,above] at (2.5,20pt) {$\rho_3$};


        \end{tikzpicture}
    \end{center}


\end{document}

但随后它产生了下面的图像 在此处输入图片描述

如您所见,绿线的位置不再正确。我没有缩放图片,所以我不知道出了什么问题。

答案1

问题在于不同的字体大小(12pt在主文件中)和图表文件中的默认 10pt 字体大小,因为您使用它们\textwidth来调整多边形的大小,并且此长度取决于文档的默认字体大小。您可以删除字体大小依赖性,例如通过使用明确的长度进行更改\textwidth(在子文件中,它的长度为 345pt),或者使用standalone 包裹(!)在主文档中使用选项obeyclassoptions,然后使用它\includestandalone{filebasename}来包含图表文件。standalone然后,在包含子文件中的代码时,包将自动切换到默认字体大小。

\documentclass[oneside, a4paper, 12pt]{article}

\usepackage[obeyclassoptions]{standalone}
\usepackage{ifthen}
\usepackage{tikz-cd}
\usepackage{tikz}
\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}
    \includestandalone{q470062_sub}% here q470062_sub.tex contains the TikZ picture, change to the used filename
    \end{center}


\end{document}

进一步的standalone包选项在这里可能会有所帮助,请检查手册中subpreambles有关自动收集子文件前导码的选项。

如果您在包前adjustbox使用该选项加载包,您还可以使用使内容居中以及其他键来修改图表的大小等。exportstandalone\includestandalone[center]{q470062_sub}adjustbox


如果这对您来说太复杂,那么只需再次减小字体大小即可tikzpicture。在 12pt 文档中,\footnotesize宏会再次为您提供 10pt。将其直接放在前面\begin{tikzpicture},并确保它周围有一个组,就像现在由于环境而形成的组一样center

答案2

Martin Scharrer 的评论和回答已经分析了您的问题是由不同的字体大小引起的。以下是解决问题的最小侵入性尝试:

    \documentclass[oneside, a4paper,12pt]{article}

\usepackage{ifthen}
\usepackage{tikz-cd}
\usepackage{tikz}
\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}
    \begin{tikzpicture}
    %Polygon 12 Seiten
    \node[fill=gray!10] (pol) [ 
    %draw, 
    minimum size=0.9\textwidth, regular polygon, regular polygon sides=12, rotate=195 ]{};
    \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/1/3} %inverse \beta's
    \draw[black!10!blue,auto=right,-<-]
    (pol.corner \x)--(pol.corner \y)
    node[black!10!blue,midway]{$\beta_{\i}$};

        \coordinate(mycord) at (0,-6.15);

    %\xi's
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
    (mycord) --(-2.21,-0.63) node[midway, left] {$\xi_1$} ;
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
    (mycord) -- (0,-20pt) node[midway, left] {$\xi_2$};
    \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}] 
    (mycord) -- (2.21,-0.63) node[midway, left] {$\xi_3$};

    % 3 Kreise mit Beschriftung
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (-2.5,0) circle (20pt)  ;
    \node[violet,above] at (-2.5,20pt) {$\rho_1$};
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (0,0) circle (20pt);
    \node[violet,above] at (0,20pt) {$\rho_2$};
    \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
    postaction={decorate},fill=white] (2.5,0) circle (20pt);
    \node[violet,above] at (2.5,20pt) {$\rho_3$};



    \end{tikzpicture}
    \end{center}

\end{document}

答案3

我能够使用 (pol.corner 1) 消除字体大小依赖性。

以下代码产生了所需的结果。

\documentclass[oneside, a4paper,12pt]{article}

\usepackage{ifthen}
\usepackage{tikz-cd}
\usepackage{tikz}
\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}
        \begin{tikzpicture}
        %Polygon 12 Seiten
        \node[fill=gray!10] (pol) [ 
        %draw, 
        minimum size=0.9\textwidth, regular polygon, regular polygon sides=12, rotate=195 ]{};
        \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/1/3} %inverse \beta's
        \draw[black!10!blue,auto=right,-<-]
        (pol.corner \x)--(pol.corner \y)
        node[black!10!blue,midway]{$\beta_{\i}$};

        %\xi's
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
        (pol.corner 1) --(-2.21,-0.63) node[midway, left] {$\xi_1$} ;
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}]  
        (pol.corner 1) -- (0,-20pt) node[midway, left] {$\xi_2$};
        \draw[black!40!green,decoration={ markings, mark=at position 0.5 with {\arrow{stealth}}}, postaction={decorate}] 
        (pol.corner 1) -- (2.21,-0.63) node[midway, left] {$\xi_3$};

        % 3 Kreise mit Beschriftung
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (-2.5,0) circle (20pt)  ;
        \node[violet,above] at (-2.5,20pt) {$\rho_1$};
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (0,0) circle (20pt);
        \node[violet,above] at (0,20pt) {$\rho_2$};
        \draw[violet,decoration={markings, mark=at position 0.26 with {\arrow[>=stealth]{<}}},
        postaction={decorate},fill=white] (2.5,0) circle (20pt);
        \node[violet,above] at (2.5,20pt) {$\rho_3$};


        \end{tikzpicture}
    \end{center}


\end{document}

相关内容