我想在两个tikzpicture
子图中分别绘制一个连接 - 在以下 MWE 中,在节点n1
和之间n3
。我认为我的代码很有意义:
\documentclass[a4paper, 12pt]{article}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows, decorations.pathreplacing, calc, chains, shapes.misc}
\begin{document}
some text some more text
\begin{figure*}
%left subfigure
\begin{subfigure}[t]{.45\textwidth}
\begin{tikzpicture}[remember picture]
\node[draw, red] (n1) at (0,0) {};
\end{tikzpicture}
\caption{Caption A}
\end{subfigure}
%
\hfill
% right subfigure
\begin{subfigure}[t]{.45\textwidth}
\begin{tikzpicture}[remember picture]
\node[draw, red] (n2) at (0,0) {};
\node[draw, red] (n3) at (1,1) {};
\end{tikzpicture}
\caption{Caption B}
\end{subfigure}
\begin{tikzpicture}[overlay]
\draw[blue] (n1) -- (n2);
\end{tikzpicture}
\caption{Some caption for A and B.}
\end{figure*}
\end{document}
然而,结果告诉我我错了(请注意最顶部的蓝线)::)
但我不知道我做错了什么。
答案1
尝试这样做:
\documentclass[a4paper, 12pt]{article}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows, decorations.pathreplacing, calc, chains, shapes.misc}
\begin{document}
some text some more text
\begin{figure*}
%left subfigure
\begin{subfigure}[t]{.45\textwidth}
\centering
\begin{tikzpicture}[remember picture]
\node[draw, red] (n1) at (0,0) {};
\end{tikzpicture}
\caption{Caption A}
\end{subfigure}
%
\hfill
% right subfigure
\begin{subfigure}[t]{.45\textwidth}
\centering
\begin{tikzpicture}[remember picture]
\node[draw, red] (n2) at (0,0) {};
\node[draw, red] (n3) at (1,1) {};
\end{tikzpicture}
\caption{Caption B}
\end{subfigure}
\begin{tikzpicture}[overlay, remember picture]
\draw[blue] (n1) -- (n2);
\end{tikzpicture}
\caption{Some caption for A and B.}
\end{figure*}
\end{document}