最后一个子图的位置在图中有所不同

最后一个子图的位置在图中有所不同

我想要一个图中的多个图形(在这个例子中是四个),并使用以下代码尝试:

\usepackage{subcaption}

\begin{figure}[h]
  \begin{subfigure}[b]{0.4\textwidth}
        \centering
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);

    \end{tikzpicture}
    \subcaption{Picture 1}
    \label{fig:1}
  \end{subfigure}
  %
  \begin{subfigure}[b]{0.4\textwidth}
        \centering
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);

    \end{tikzpicture}
    \subcaption{Picture 2}
    \label{fig:2}
  \end{subfigure}
%
  \begin{subfigure}[b]{0.4\textwidth}
        \centering
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);

    \end{tikzpicture}
    \subcaption{Picture 1}
    \label{fig:1}
  \end{subfigure}
%
  \begin{subfigure}[b]{0.4\textwidth}
        \centering
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);

    \end{tikzpicture}
    \subcaption{Picture 1}
    \label{fig:1}
  \end{subfigure}
  \caption{Pictures}
  \label{all sub assigns}
\end{figure}

得到下图的结果: 在此处输入图片描述

但是,我希望子图 (d) 位于正下方的角落,就像子图 (b) 一样。 我的第一个问题是如何实现这一点。

我的第二个问题是否可以在每个子图周围添加一个框架,但不能在大图本身周围添加一个框架。

如果有人还有时间,我的第三个问题如何定位三个或四个子图,使子图仍然正确分离。

如果您能回答这些问题中的任何一个,我们将不胜感激。

答案1

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}

\begin{figure}
\centering
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \definecolor{myblue}{RGB}{80,80,160}
        \definecolor{mygreen}{RGB}{80,160,80}
        \begin{tikzpicture}
        [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
        \node (n7) at (8,8) {7};
        \node (n6) at (9,8) {6};
        \node (n5) at (10,8) {5};
        \node (n2) at (9,7) {2};
        \node (n3) at (10,7) {3};
        \node (n4) at (10,6) {4};
        \node (n1) at (6,6) {1};
        \node (n8) at (13,7) {8};

        \draw (n7) -- (n6);
        \draw (n6) -- (n5);
        \draw (n3) -- (n4);
        \draw (n7) -- (n2);
        \draw (n6) -- (n2);
        \draw (n5) -- (n2);
        \draw (n6) -- (n3);
        \draw (n5) -- (n3);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);

        \end{tikzpicture}
        \subcaption{Picture 1}
        \label{fig:1}
    \end{subfigure}
    %
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \definecolor{myblue}{RGB}{80,80,160}
        \definecolor{mygreen}{RGB}{80,160,80}
        \begin{tikzpicture}
        [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
        \node (n7) at (8,8) {7};
        \node (n6) at (9,8) {6};
        \node (n5) at (10,8) {5};
        \node (n2) at (9,7) {2};
        \node (n3) at (10,7) {3};
        \node (n4) at (10,6) {4};
        \node (n1) at (6,6) {1};
        \node (n8) at (13,7) {8};

        \draw (n7) -- (n6);
        \draw (n6) -- (n5);
        \draw (n3) -- (n4);
        \draw (n7) -- (n2);
        \draw (n6) -- (n2);
        \draw (n5) -- (n2);
        \draw (n6) -- (n3);
        \draw (n5) -- (n3);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);

        \end{tikzpicture}
        \subcaption{Picture 2}
        \label{fig:2}
    \end{subfigure}

    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \definecolor{myblue}{RGB}{80,80,160}
        \definecolor{mygreen}{RGB}{80,160,80}
        \begin{tikzpicture}
        [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
        \node (n7) at (8,8) {7};
        \node (n6) at (9,8) {6};
        \node (n5) at (10,8) {5};
        \node (n2) at (9,7) {2};
        \node (n3) at (10,7) {3};
        \node (n4) at (10,6) {4};
        \node (n1) at (6,6) {1};
        \node (n8) at (13,7) {8};

        \draw (n7) -- (n6);
        \draw (n6) -- (n5);
        \draw (n3) -- (n4);
        \draw (n7) -- (n2);
        \draw (n6) -- (n2);
        \draw (n5) -- (n2);
        \draw (n6) -- (n3);
        \draw (n5) -- (n3);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);

        \end{tikzpicture}
        \subcaption{Picture 1}
        \label{fig:1}
    \end{subfigure}
%
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \definecolor{myblue}{RGB}{80,80,160}
        \definecolor{mygreen}{RGB}{80,160,80}
        \begin{tikzpicture}
        [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
        \node (n7) at (8,8) {7};
        \node (n6) at (9,8) {6};
        \node (n5) at (10,8) {5};
        \node (n2) at (9,7) {2};
        \node (n3) at (10,7) {3};
        \node (n4) at (10,6) {4};
        \node (n1) at (6,6) {1};
        \node (n8) at (13,7) {8};

        \draw (n7) -- (n6);
        \draw (n6) -- (n5);
        \draw (n3) -- (n4);
        \draw (n7) -- (n2);
        \draw (n6) -- (n2);
        \draw (n5) -- (n2);
        \draw (n6) -- (n3);
        \draw (n5) -- (n3);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);

        \end{tikzpicture}
        \subcaption{Picture 1}
        \label{fig:1}
    \end{subfigure}
    \caption{Pictures}
    \label{all sub assigns}
\end{figure}

\end{document}

在此处输入图片描述

四个排成一排(这里也有一个框架):

\begin{figure}
\centering
\makebox[\linewidth]{%
    \fbox{\begin{subfigure}[b]{0.4\textwidth}
     ...
      \end{subfigure}%
    }% end \fbox
    \fbox{...
    ...
    \% end \fbox
 }% end \makebox
\end{figure}

在此处输入图片描述

答案2

使用 TikZ 创建图形时,最简单的方法是使用 Tikz 的所有功能来定位它们。为此,只需将它们分别放置在scope (参见 3.0.1a 手册第 126 页)。为了构造它们,我们用键将其命名为scopelocal bounding box请参阅手册第 1033 页),然后使用它来放置caption文本和。framescope

优点是所有这些位置都是相对的:通过移动scopescaption文本和frame正确地放置在所需的位置。

不是知道你是否想要标题文字Picture 1,,Picture 2Picture 3里面框架或外部,我已经举例说明了两种可能性。

捕获

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}
\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\begin{scope}[local bounding box= upleft]
\node (n7) at (8,8) {7};
\node (n6) at (9,8) {6};
\node (n5) at (10,8) {5};
\node (n2) at (9,7) {2};
\node (n3) at (10,7) {3};
\node (n4) at (10,6) {4};
\node (n1) at (6,6) {1};
\node (n8) at (13,7) {8};

\draw (n7) -- (n6);
\draw (n6) -- (n5);
\draw (n3) -- (n4);
\draw (n7) -- (n2);
\draw (n6) -- (n2);
\draw (n5) -- (n2);
\draw (n6) -- (n3);
\draw (n5) -- (n3);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\node[below=3mm of upleft,rectangle, fill=none]{Picture 1};
\end{scope}

\draw([shift={(-.2,-.2)}]upleft.south west)rectangle([shift={(.2,.2)}]upleft.north east);


\begin{scope}[shift={(9,0)},local bounding box= upright]
\node (n7) at (8,8) {7};
\node (n6) at (9,8) {6};
\node (n5) at (10,8) {5};
\node (n2) at (9,7) {2};
\node (n3) at (10,7) {3};
\node (n4) at (10,6) {4};
\node (n1) at (6,6) {1};
\node (n8) at (13,7) {8};

\draw (n7) -- (n6);
\draw (n6) -- (n5);
\draw (n3) -- (n4);
\draw (n7) -- (n2);
\draw (n6) -- (n2);
\draw (n5) -- (n2);
\draw (n6) -- (n3);
\draw (n5) -- (n3);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\node[below=3mm of upright,rectangle, fill=none]{Picture 2};
\end{scope}
\draw([shift={(-.2,-.2)}]upright.south west)rectangle([shift={(.2,.2)}]upright.north east);


\begin{scope}[shift={(0,-5)},local bounding box= downleft]
\node (n7) at (8,8) {7};
\node (n6) at (9,8) {6};
\node (n5) at (10,8) {5};
\node (n2) at (9,7) {2};
\node (n3) at (10,7) {3};
\node (n4) at (10,6) {4};
\node (n1) at (6,6) {1};
\node (n8) at (13,7) {8};

\draw (n7) -- (n6);
\draw (n6) -- (n5);
\draw (n3) -- (n4);
\draw (n7) -- (n2);
\draw (n6) -- (n2);
\draw (n5) -- (n2);
\draw (n6) -- (n3);
\draw (n5) -- (n3);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\end{scope}
\node[below=3mm of downleft,rectangle, fill=none]{Picture 3};
\draw([shift={(-.2,-.2)}]downleft.south west)rectangle([shift={(.2,.2)}]downleft.north east);

\begin{scope}[shift={(9,-5)},local bounding box= downright]
\node (n7) at (8,8) {7};
\node (n6) at (9,8) {6};
\node (n5) at (10,8) {5};
\node (n2) at (9,7) {2};
\node (n3) at (10,7) {3};
\node (n4) at (10,6) {4};
\node (n1) at (6,6) {1};
\node (n8) at (13,7) {8};

\draw (n7) -- (n6);
\draw (n6) -- (n5);
\draw (n3) -- (n4);
\draw (n7) -- (n2);
\draw (n6) -- (n2);
\draw (n5) -- (n2);
\draw (n6) -- (n3);
\draw (n5) -- (n3);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\end{scope}
\node[below=3mm of downright,rectangle, fill=none]{Picture 4};
\draw([shift={(-.2,-.2)}]downright.south west)rectangle([shift={(.2,.2)}]downright.north east);

\end{tikzpicture}

\end{document}

使用 www.DeepL.com/Translator 翻译

答案3

4 个环境的内容subfigure都比 宽0.4\textwidth。请注意,指定环境的宽度subfigure不会不是暗示其内容将适合指定的宽度。

我建议您(a)让subfigure环境更宽一些(0.45\textwidth比如说),(b)\centering\raggedright and\raggedleft , respectively, and (c) maximize the horizontal separation between the subfigures via\hfill` 指令替换。

以下屏幕截图中的框架线是通过加载geometry带有选项的包生成的showframe。对于真实文档的最终版本,请务必省略该showframe选项。

在此处输入图片描述

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{subcaption,tikz}
\begin{document}
\begin{figure}[h]
  \begin{subfigure}[b]{0.45\textwidth}
    \raggedright
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
    \end{tikzpicture}
    \subcaption{Picture 1}
    \label{fig:1}
  \end{subfigure}%
  \hfill
  \begin{subfigure}[b]{0.45\textwidth}
    \raggedleft
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
    \end{tikzpicture}
    \subcaption{Picture 2}
    \label{fig:2}
  \end{subfigure}

  \bigskip

  \begin{subfigure}[b]{0.45\textwidth}
    \raggedright
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
    \end{tikzpicture}
    \subcaption{Picture 3}
    \label{fig:3}
  \end{subfigure}%
  \hfill
  \begin{subfigure}[b]{0.45\textwidth}
    \raggedleft
    \definecolor{myblue}{RGB}{80,80,160}
    \definecolor{mygreen}{RGB}{80,160,80}
    \begin{tikzpicture}
      [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
      \node (n7) at (8,8) {7};
      \node (n6) at (9,8) {6};
      \node (n5) at (10,8) {5};
      \node (n2) at (9,7) {2};
      \node (n3) at (10,7) {3};
      \node (n4) at (10,6) {4};
      \node (n1) at (6,6) {1};
      \node (n8) at (13,7) {8};

      \draw (n7) -- (n6);
      \draw (n6) -- (n5);
      \draw (n3) -- (n4);
      \draw (n7) -- (n2);
      \draw (n6) -- (n2);
      \draw (n5) -- (n2);
      \draw (n6) -- (n3);
      \draw (n5) -- (n3);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
    \end{tikzpicture}
    \subcaption{Picture 4}
    \label{fig:4}
  \end{subfigure}
\caption{Pictures}
\label{all sub assigns}
\end{figure}
\end{document} 

相关内容