我在用虚线连接两个图形时遇到了问题。Latex 语法如下图所示。
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.4\linewidth}
\begin{tikzpicture}
\draw[->] (-0.5, 0) -- (4, 0) node[right] {$M$};
\draw[->] (0, -0.5) -- (0, 4) node [above] {$i$};
\draw (1.5, 0) -- (1.5, 3.75) node [above] {$M_s$}
\draw (2.5, 0) -- (2.5, 3.75) node [above] {$M_s'$}
\draw (0.5, 4) to [bend right =45] (4, 0.5) node[right] {$L$}
\end{tikzpicture}
\caption{1} \label{fig:my_label1}
\end{subfigure}
\begin{subfigure}[b]{0.4\linewidth}
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (4,0) node[right] {$I$};
\draw[->] (0,-0.5) -- (0,4) node[above] {$r$};
\draw (0.5, 4) to [bend right =45] (4, 0.5) node[right] {$r$}
\end{tikzpicture}
\caption{Interaction} \label{fig:M2}
\end{subfigure}
\caption{Ravnotežni obseg investicij}
\end{figure}
答案1
欢迎!您需要overlay
一张remember
图片,但您可能还需要计算交点。以下代码可以做到这一点,并修复代码中的错误并将其完成为可编译的示例。
\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.45\linewidth}
\begin{tikzpicture}[remember picture]
\draw[->] (-0.5, 0) -- (4, 0) node[right] {$M$};
\draw[->] (0, -0.5) -- (0, 4) node [above] {$i$};
\draw[name path=vert1] (1.5, 0) -- (1.5, 3.75) node [above] {$M_s$};
\draw (2.5, 0) -- (2.5, 3.75) node [above] {$M_s'$};
\draw[name path=curve1] (0.5, 4) to [bend right=45] (4, 0.5) node[right] {$L$};
\path[name intersections={of=vert1 and curve1,by=i1}] (0,0) coordinate (O1);
\end{tikzpicture}
\caption{1}
\label{fig:my_label1}
\end{subfigure}\qquad
\begin{subfigure}[b]{0.45\linewidth}
\begin{tikzpicture}[remember picture]
\draw[->] (-0.5,0) -- (4,0) node[right] {$I$} coordinate (x2);
\draw[->] (0,-0.5) -- (0,4) node[above] {$r$};
\draw[name path=curve2] (0.5, 4) to [bend right =45] (4, 0.5) node[right] {$r$};
\path[overlay,name path=hori] (O1|-i1) -- (x2|-i1);
\draw[name intersections={of=hori and curve2,by=i2},overlay,densely dotted]
(O1|-i1) --(i2);
\end{tikzpicture}
\caption{Interaction}
\label{fig:M2}
\end{subfigure}
\caption{Ravnotezni obseg investicij.}
\end{figure}
\end{document}