
各グラフを隣り合わせに保ちながら、各グラフの下にキャプションを追加するにはどうすればよいですか?
\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
これを実現する方法はたくさんあります。キャプションをまったく付けない場合は、M S の回答を使用できますが、環境は使用せずfigure
、minipage
の代わりにを使用しsubfigure
、 の直後にテキストを記述するだけです( は使用\end{tikzpicture}
しません) \caption
。ただし、テキストの前に空行 (段落区切り) を追加します。
ここでは、 を 1 つ使用しtikzpicture
、 2 番目の図を で右に移動したまったく異なるアプローチを示します\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
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
下記のコードが目的にかなうことを願っています。基本的には 1 つの図と 2 つのサブキャプションです。キャプション付きの 2 つの異なる図が必要な場合は、お知らせください。
最近のコメントに基づきます。メイン図のキャプション部分にコメントできます。
\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}
出力: