双重构建后 Tikz 节点移动

双重构建后 Tikz 节点移动

我想使用 groupplot 在 2x2 网格中的一个 tikzpicture 中绘制 4 个图形。我还想在前三个图中的节点到最后一个图中的节点之间放置一些箭头。为此,我尝试使用remember pictureoverlay,但可能我设置不正确。

当我构建输出时,经过一次编译,我得到了正确的图和箭头,但如果我编译两次,箭头就会移动到其他坐标。此外,如果我做了一些更改,例如在节点坐标中,仅通过一次编译,输出不会更新,但我必须删除构建过程中创建的临时文件,然后进行编译。

为什么会这样?我想避免这个手动删除过程,并在多次编译后获得正确的箭头。

这是 MWE。可能有些包是无用的/多余的。

\documentclass{article}
\usepackage[dvips]{graphicx}
\usepackage[usenames,dvipsnames]{xcolor} % in order to use color names
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{color}
\usepackage{psfrag}
\usepackage{rotating}
\usepackage{pgf,pgfsys,pgffor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\usepackage[caption=false]{subfig}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows,decorations.pathmorphing,backgrounds,fit,mindmap,calc,through,scopes,fadings,positioning,automata,calendar,shapes,er,matrix,folding,patterns,petri,plothandlers,plotmarks,shadows,topaths,through,trees,pgfplots.units,shapes.gates.logic.US,shapes.gates.logic.IEC,positioning} 
\usepgfplotslibrary{groupplots,units}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
\begin{groupplot}[
        /pgfplots/group/horizontal sep=1.75cm,
        /pgfplots/group/vertical sep=1cm,
    group style={
                group size=2 by 2},
                yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},
                xlabel=$\tau$,
        axis y line=left,
                axis x line=bottom,
                xlabel style={below},height=4cm, width=4cm
        ]
\nextgroupplot[remember picture,line width=1pt, ylabel=$\lambda_1$, ylabel style={rotate=-90},ymin=0.9,ymax=1.5]
\addplot[line width=1pt,no markers,cyan] function{x};
\draw[line width=0.5pt] (axis cs:0.1,0.9) -- (axis cs:0.1,1.19449) node (y1) {};
%
\nextgroupplot[remember picture,line width=1pt, ylabel=$t_1$, ylabel style={rotate=-90},ymin=-0.7,ymax=0.1]
\addplot[line width=1pt,no markers,cyan,domain=-0.7:0.1] function{-2*x};
\draw[line width=0.5pt] (axis cs:0.1,-0.7) -- (axis cs:0.1,-0.212258) node (t1) {};
%
\nextgroupplot[remember picture,line width=1pt, ylabel=$\lambda_2$, ylabel style={rotate=-90},ymin=1.35,ymax=1.75]
\addplot[line width=1pt,no markers,cyan] function{x};
\draw[line width=0.5pt] (axis cs:0.1,1.35) -- (axis cs:1,1.39089)  node (y2) {};
%
\nextgroupplot[name=step,remember picture,line width=1pt, ylabel=$\lambda(t)$, xlabel=$t$,xtick={-0.6,-0.3,0}, ylabel style={rotate=-90},xmin=-0.8,xmax=0.1,ymin=0.9,ymax=1.75] 
\draw[cyan, solid] (axis cs:-0.8,1.19449) -- (axis cs:-0.212258,1.19449) -- (axis cs:-0.212258,1.39089) -- (axis cs:0,1.39089);
\node[draw, line width=0.5pt] at (axis cs:-0.3,1.6) {$\tau=0.1$};
\node[inner sep=0pt] (y1end) at (axis cs:-0.5,1.19449) {};
\node[inner sep=0pt] (y2end) at (axis cs:-0.212258,1.39089) {};
\node[inner sep=0pt] (t1end) at (axis cs:-0.212258,1.2) {};
\end{groupplot}

\draw[->] (y1) .. controls +(-20:1) and +(120:1) ..  (y1end);
\draw[->] (y2) .. controls +(80:1.5) and +(160:2) .. (y2end);
\draw[->] (t1) .. controls +(-20:2) and +(15:2)  ..  (t1end);
\end{tikzpicture}

\end{document}

答案1

正如 ClaudioFiandrino 所建议的,没有密钥remember pictureoverlay代码也可以工作。

这是(几乎)MWE(可能有些包是无用或多余的)。

\documentclass{article}
\usepackage[dvips]{graphicx}
\usepackage[usenames,dvipsnames]{xcolor} 
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{color}
\usepackage{psfrag}
\usepackage{rotating}
\usepackage{pgf,pgfsys,pgffor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage[caption=false]{subfig}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows,decorations.pathmorphing,backgrounds,fit,mindmap,calc,through,scopes,fadings,positioning,automata,calendar,shapes,er,matrix,folding,patterns,petri,plothandlers,plotmarks,shadows,topaths,through,trees,pgfplots.units,shapes.gates.logic.US,shapes.gates.logic.IEC,positioning} 
\usepgfplotslibrary{groupplots,units}

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[
        /pgfplots/group/horizontal sep=1.75cm,
        /pgfplots/group/vertical sep=1cm,
    group style={
                group size=2 by 2},
                yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},
                xlabel=$\tau$,
        axis y line=left,
                axis x line=bottom,
                xlabel style={below},height=4cm, width=4cm,
        ]
\nextgroupplot[line width=1pt, ylabel=$\lambda_1$, ylabel style={rotate=-90},ymin=0.9,ymax=1.5]
\addplot[line width=1pt,no markers,cyan] function{x};
\draw[line width=0.5pt] (axis cs:0.1,0.9) -- (axis cs:0.1,1.19449) node (y1) {};
%
\nextgroupplot[line width=1pt, ylabel=$t_1$, ylabel style={rotate=-90},ymin=-0.7,ymax=0.1]
\addplot[line width=1pt,no markers,cyan,domain=-0.7:0.1] function{-2*x};
\draw[line width=0.5pt] (axis cs:0.1,-0.7) -- (axis cs:0.1,-0.212258) node (t1) {};
%
\nextgroupplot[line width=1pt, ylabel=$\lambda_2$, ylabel style={rotate=-90},ymin=1.35,ymax=1.75]
\addplot[line width=1pt,no markers,cyan] function{x};
\draw[line width=0.5pt] (axis cs:2,1.35) -- (axis cs:2,1.39089)  node (y2) {};
%
\nextgroupplot[line width=1pt, ylabel=$\lambda(t)$, xlabel=$t$,xtick={-0.6,-0.3,0}, ylabel style={rotate=-90},xmin=-0.8,xmax=0.1,ymin=0.9,ymax=1.75] 
\draw[cyan, solid] (axis cs:-0.8,1.19449) -- (axis cs:-0.212258,1.19449) -- (axis cs:-0.212258,1.39089) -- (axis cs:0,1.39089);
\node[draw, line width=0.5pt] at (axis cs:-0.3,1.6) {$\tau=0.1$};
\node[inner sep=0pt] (y1end) at (axis cs:-0.5,1.19449) {};
\node[inner sep=0pt] (y2end) at (axis cs:-0.212258,1.39089) {};
\node[inner sep=0pt] (t1end) at (axis cs:-0.212258,1.2) {};
\end{groupplot}
\draw[->] (y1) .. controls +(-20:1) and +(120:1) ..  (y1end);
\draw[->] (y2) .. controls +(80:1.5) and +(160:2) .. (y2end);
\draw[->] (t1) .. controls +(-20:2) and +(15:2)  ..  (t1end);
\end{tikzpicture}

\end{document}

这是输出的 png 版本。 在此处输入图片描述

相关内容