如何在 tikz 图形中添加虚线圆?

如何在 tikz 图形中添加虚线圆?

我的工作代码如下:

\documentclass{article}

\usepackage{tikz,tikz-cd,pgf,makecell,smartdiagram,lmodern,ragged2e,array,caption,graphicx,booktabs,tabularx,xcolor}

\usetikzlibrary{positioning}

\begin{document}
    \tikzstyle{block} = [rectangle, rounded corners, thick, align=center, fill=orange!40, text width=3.5cm]
    
    \begin{figure}[!h]
        \centering
        \resizebox{.8\linewidth}{!}{
            \begin{tikzpicture}[thick, node distance = 5cm,]
                % Place nodes
                \node [block] (MC) {Magnetic\\ Contour plane\\($\mathbf{MC}$)};
                \node [block, right of=MC, node distance=6cm] (TM) {Topographic Magnetic Field\\($\mathbf{TM})$}; 
                \node [block, below of=MC, node distance=3cm] (BM) {Base\\ Magnetic Field\\($\mathbf{BM}$)}; 
                \node [block, right of=BM, node distance=6cm] (FM) {Fuzzy\\ Magnetic Field\\($\mathbf{FM})$}; 
                \node [right of=MC, node distance=3cm, yshift=0.3cm] (a) {$\cong$}; 
                \node [right of=BM, node distance=3cm, yshift=-0.3cm] (b) {$\cong$}; 
                \node [below of=MC, node distance=1.5cm, xshift=-0.3cm] (c) {$\cong$}; 
                \node [below of=TM, node distance=1.5cm, xshift=0.3cm] (d) {$\cong$}; 
                
                %draw arrow         
                \draw[line width=1pt,->] (MC) -- (TM);
                \draw[line width=1pt,->] (MC) -- (BM);
                \draw[line width=1pt,->] (BM) -- (FM);
                \draw[line width=1pt,->] (FM) -- (TM);
            \end{tikzpicture}
        }
    \end{figure}
    
\end{document}

产生:

在此处输入图片描述

我想在图中放置一个虚线圆圈,如下所示:

在此处输入图片描述

我该如何实现这一点?请帮忙。

答案1

就像这样:

在此处输入图片描述

通过使用库arrows.meta(用于箭头)、fit(用于在框上绘制椭圆)、positioning(用于使用其语法定位框)、quotes(用于箭头上的标签)和shapes.geomeric(用于框周围的椭圆):

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                fit,
                positioning,
                quotes,
                shapes.geometric}

\begin{document}

    \begin{figure}[!h]
    \centering
    \begin{tikzpicture}[auto,
node distance = 22mm and 22mm,
   box/.style = {rectangle, rounded corners, fill=orange!40, 
                 text width=3.5cm, align=center},
     E/.style = {ellipse, draw=red, very thick, dashed, 
                 inner sep=-1ex},
every edge/.style = {draw, -{Straight Barb[scale=0.8]}, very thick}
                        ]
% Place nodes
    \begin{scope}[nodes=box]
\node (MC) {Magnetic\\ Contour plane\\($\mathbf{MC}$)};
\node [right=of MC] (TM) {Topographic Magnetic Field\\($\mathbf{TM})$};
\node [below=of MC] (BM) {Base\\ Magnetic Field\\($\mathbf{BM}$)};
\node [right=of BM] (FM) {Fuzzy\\ Magnetic Field\\($\mathbf{FM})$};
    \end{scope}
% links
\draw   (MC) edge ["$\cong$"]   (TM)
        (MC) edge ["$\cong$"]   (BM)
        (BM) edge ["$\cong$"]   (FM)
        (FM) edge ["$\cong$"]   (TM);
% elipse
\node [E, fit=(MC)] {};
    \end{tikzpicture}
    \end{figure}

\end{document}

通过将提出的解决方案与您的 MWE(最小工作示例)进行比较,您可以观察到,使用positioning syntax (for exampleright=of MC insteadright of=MC is not needed anymore scaling your image, usingquotes` 进行标记可以使您的代码更短。

相关内容