두 그래프에 캡션을 나란히 추가

두 그래프에 캡션을 나란히 추가

각 그래프를 나란히 유지하면서 각 그래프 아래에 캡션을 추가하려면 어떻게 해야 합니까?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{positioning}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
    \begin{center}
        \begin{tikzpicture}
            \node[main node, label=above:{$a$},] (1) {};
            \node[main node, label=right:{$b$}] (2) [below right = 1cm and 1cm of 1] {};
            \node[main node, label=left:{$c$}] (3) [below left = 1cm and 1cm of 1] {};

            \path[draw, thick]
            (1) edge node {} (2)
            (2) edge node {} (3)
            (1) edge node {} (3);
        \end{tikzpicture} \hspace{2cm}
        \begin{tikzpicture}
            \node[main node, label=left:{$a$},] (1) {};
            \node[main node, label=left:{$b$}] (2) [below = 1cm of 1] {};
            \node[main node, label=right:{$c$}] (3) [right = 1cm of 1] {};
            \node[main node, label=right:{$d$}] (4) [below = 1 cm of 3] {};

            \path[draw, thick]
            (1) edge node {} (2)
            (2) edge node {} (4)
            (3) edge node {} (4)
            (1) edge node {} (3);
        \end{tikzpicture}
    \end{center}
\end{document}

여기에 이미지 설명을 입력하세요

답변1

이를 달성하는 방법에는 여러 가지가 있습니다. 캡션이 전혀 없는 경우 MS의 답변을 사용할 수 있지만 환경을 사용하지 않고 대신 figure사용 하고 바로 뒤에 텍스트를 쓸 수 있습니다 . 하지만 텍스트 앞에 빈 줄(문단 나누기)을 추가합니다.minipagesubfigure\end{tikzpicture}\caption

여기서는 단일 을 사용한 완전히 다른 접근 방식을 보여 주며 tikzpicture, 두 번째 다이어그램은 을 사용하여 오른쪽으로 이동했습니다 \begin{scope}[xshift=5cm, local bounding box=b]. 는 텍스트와 함께 를 배치하는 데 사용하는 의 local bounding box내용 주위에 맞는 노드를 만듭니다 .scope\node

또 다른 세부 사항: 일반적으로 \usetikzlibrary{..}after 를 사용하지 마세요 \begin{document}. 여기서는 문제가 되지 않는 것 같은데, 안 되는 경우를 본 적이 있으니 프리앰블에 라이브러리를 로드하는 것이 좋습니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
    \begin{center}
        \begin{tikzpicture}[
            captiontext/.style={below=3mm, text width=5cm}
            ]
            \node[main node, label=above:{$a$}] (1) {};
            \node[main node, label=right:{$b$}, below right = 1cm and 1cm of 1] (2)  {};
            \node[main node, label=left:{$c$}, below left = 1cm and 1cm of 1] (3) {};

            \draw [thick] (1) -- (2) -- (3) -- (1);
            
            \node [captiontext] at (current bounding box.south) {Text text and more text ad infinitum and so on.};


        \begin{scope}[xshift=5cm, local bounding box=b]
            \node[main node, label=left:{$a$},] (1) {};
            \node[main node, label=left:{$b$},below = 1cm of 1] (2)  {};
            \node[main node, label=right:{$c$}, right = 1cm of 1] (3)  {};
            \node[main node, label=right:{$d$}, below = 1 cm of 3] (4)  {};

            \draw [thick] (1) -- (2) -- (4) -- (3) -- (1);
            \end{scope}
            
            \node [captiontext] at (b.south) {More text text and more text ad infinitum and so on going on for a bit.};
        \end{tikzpicture}
    \end{center}
\end{document}

답변2

두 개의 미니페이지를 나란히 사용할 수 있습니다. 해결해야 할 문제는 사진과 캡션의 세로 크기가 달라도 캡션이 동일한 수준으로 표시되도록 하는 것입니다.

내 해결책은 하단 정렬을 사용하여 중첩된 미니페이지에 그림을 삽입하는 것입니다. 대신 외부 미니페이지에는 위쪽 정렬이 있습니다. 이는 실제로 해당 참조 지점이 위쪽 상자의 참조 지점, 즉 그림의 아래쪽이 됨을 의미합니다. 이렇게 하면 캡션이 페이지의 동일한 수직 위치에 배치됩니다.

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

\tikzset{
  main node/.style={
    circle,
    fill=black,
    draw,
    minimum size=.2cm,
    inner sep=0pt
  },
}

\begin{document}

\begin{figure}

\begin{minipage}[t]{0.45\textwidth}
% left column
  \begin{minipage}[b]{\textwidth}
  \centering
  \begin{tikzpicture}
    \node[main node, label=above:{$a$},] (1) {};
    \node[main node, label=right:{$b$}] (2) [below right = 1cm and 1cm of 1] {};
    \node[main node, label=left:{$c$}] (3) [below left = 1cm and 1cm of 1] {};

    \path[draw, thick]
      (1) edge node {} (2)
      (2) edge node {} (3)
      (1) edge node {} (3);
    \end{tikzpicture}
  \end{minipage}

  \caption{This is the figure on the left, with a not so lengthy caption}
\end{minipage}\hfill % <--- don't forget
\begin{minipage}[t]{0.45\textwidth}
% right column
  \begin{minipage}[b]{\textwidth}
  \centering
  \begin{tikzpicture}
    \node[main node, label=left:{$a$},] (1) {};
    \node[main node, label=left:{$b$}] (2) [below = 1cm of 1] {};
    \node[main node, label=right:{$c$}] (3) [right = 1cm of 1] {};
    \node[main node, label=right:{$d$}] (4) [below = 1 cm of 3] {};

    \path[draw, thick]
      (1) edge node {} (2)
      (2) edge node {} (4)
      (3) edge node {} (4)
      (1) edge node {} (3);
  \end{tikzpicture}
  \end{minipage}

  \caption{This is the figure on the right, with a long caption,
    that should form at least three lines; we add text so that
    it's long enough}
\end{minipage}

\end{figure}

\end{document}

여기에 이미지 설명을 입력하세요

답변3

아래에 언급된 코드가 귀하의 목적에 부합하기를 바랍니다. 기본적으로 두 개의 하위 캡션이 있는 단일 그림입니다. 캡션이 포함된 두 개의 다른 그림이 필요한 경우 알려주십시오.

최근 댓글을 바탕으로 작성되었습니다. 주요 그림 캡션 부분에 댓글을 달 수 있습니다.

\documentclass{article}
\usepackage{tikz,subcaption}
\begin{document}
\usetikzlibrary{positioning}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\linewidth}
\centering
\begin{tikzpicture}
        \node[main node, label=above:{$a$},] (1) {};
        \node[main node, label=right:{$b$}] (2) [below right = 1cm and 1cm of 1] {};
        \node[main node, label=left:{$c$}] (3) [below left = 1cm and 1cm of 1] {};
        \path[draw, thick]
        (1) edge node {} (2)
        (2) edge node {} (3)
        (1) edge node {} (3);
    \end{tikzpicture} 
    \caption{caption1} \label{fig:M1} 
    \end{subfigure}
    \begin{subfigure}[b]{0.4\linewidth}
        \centering
   \begin{tikzpicture}
        \node[main node, label=left:{$a$},] (1) {};
        \node[main node, label=left:{$b$}] (2) [below = 1cm of 1] {};
        \node[main node, label=right:{$c$}] (3) [right = 1cm of 1] {};
        \node[main node, label=right:{$d$}] (4) [below = 1 cm of 3] {};
        \path[draw, thick]
        (1) edge node {} (2)
        (2) edge node {} (4)
        (3) edge node {} (4)
        (1) edge node {} (3);
    \end{tikzpicture}  
\caption{caption2} \label{fig:M2}  
\end{subfigure}
\caption{main caption}  
\end{figure}   
\end{document}

출력:

여기에 이미지 설명을 입력하세요

관련 정보