
如何在每個圖表下方新增標題,同時保持它們彼此相鄰?
\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
,而是使用minipage
代替,然後直接在, nosubfigure
後面寫入文本。不過,在文字之前加入一個空白行(分段符)。\end{tikzpicture}
\caption
在這裡,我展示了一種完全不同的方法,使用單個tikzpicture
,第二個圖使用 移到右側\begin{scope}[xshift=5cm, local bounding box=b]
。創建local bounding box
一個適合 的內容的節點scope
,我用它來定位 a\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}
輸出: