![wrapfig 环境中并排放置的两个 TiKZ 图形](https://linux22.com/image/450216/wrapfig%20%E7%8E%AF%E5%A2%83%E4%B8%AD%E5%B9%B6%E6%8E%92%E6%94%BE%E7%BD%AE%E7%9A%84%E4%B8%A4%E4%B8%AA%20TiKZ%20%E5%9B%BE%E5%BD%A2.png)
我正尝试将两个 tikz 图形并排放置在 wrapfig 环境中。
以下是 MWE:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{wrapfig}
\usepackage{lipsum}
\usetikzlibrary{shapes,decorations,arrows,calc,arrows.meta,fit,positioning}
\tikzset{
-Latex,auto,node distance =1 cm and 1 cm,semithick,
state/.style ={ellipse, draw, minimum width = 0.7 cm},
point/.style = {circle, draw, inner sep=0.04cm,fill,node contents={}},
bidirected/.style={Latex-Latex,dashed},
el/.style = {inner sep=2pt, align=left, sloped}
}
\begin{document}
\lipsum[1-2]
\begin{wrapfigure}{r}{0.4\textwidth}
\centering
\begin{subfigure}[t]{0.4\textwidth}
\centering
\begin{tikzpicture}[node distance =1cm and 1.3cm]
\node (X0) [label=left:{$X$},point];
\node (Z0) [label=left:{$Z$},below of = X0,point];
\node (Y0) [label=left:{$Y$},below of = Z0,point];
\path (X0) edge (Z0);
\path (Z0) edge (Y0);
\path[bidirected] (X0) edge[bend left=50] (Z0);
\end{tikzpicture}
\caption{Unidentifiable}
\end{subfigure}
%
\begin{subfigure}[t]{0.4\textwidth}
\centering
\begin{tikzpicture}[node distance =1cm and 1.3cm]
\node (X0) [label=left:{$X$},point];
\node (Z0) [label=left:{$Z$},below of = X0,point];
\node (Y0) [label=left:{$Y$},below of = Z0,point];
\path (X0) edge (Z0);
\path (Z0) edge (Y0);
\path[bidirected] (X0) edge[bend left=50] (Y0);
\end{tikzpicture}
\caption{Identifiable}
\end{subfigure}
\caption{Write me}
\label{fig:ID_examples}
\end{wrapfigure}
\end{document}
可以预见的是,这不起作用,因为子图是堆叠的,而不是并排的。我哪里做错了?
答案1
编辑: 现在子图是并排的。
- 在纯
standalone
文档中wrapfigure
不起作用。至少你需要添加varwidth
选项。 wrapfig
应在您想要所在的段落之前插入A。- 为了使用
subfigure
您需要添加到前言subcaption
包中。 subfigure should be less than half of
包裹图的宽度- 为了更好地放置子标题,您需要增加
wrapfigure
宽度(如果您使用article
documentclass)。
使用文档类的 MWE article
,在“wrapfigure”中并排显示子图:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc,
decorations,
fit,
positioning,
shapes}
\tikzset{auto,
> = Latex,
semithick,
node distance = 12mm and 22mm,
state/.style = {ellipse, draw, minimum width = 7mm},
point/.style = {circle, fill, inner sep=2pt,
node contents={}},
}
\usepackage{wrapfig}
\usepackage{subcaption}
\usepackage{lipsum}
\begin{document}
\begin{wrapfigure}{r}{0.44\textwidth}
\centering
\begin{subfigure}[t]{0.48\linewidth}
\centering
\begin{tikzpicture}
\node (X0) [label=left:{$X$},point];
\node (Z0) [label=left:{$Z$},below=of X0, point];
\node (Y0) [label=left:{$Y$},below=of Z0, point];
%
\path (X0) edge (Z0)
(Z0) edge (Y0);
\path[<->, dashed] (X0) edge[bend left=50] (Z0);
\end{tikzpicture}
\caption{Unidentifiable}
\end{subfigure}
%
\begin{subfigure}[t]{0.48\linewidth}
\centering
\begin{tikzpicture}
\node (X0) [label=left:{$X$},point];
\node (Z0) [label=left:{$Z$},below=of X0,point];
\node (Y0) [label=left:{$Y$},below=of Z0,point];
\path (X0) edge (Z0)
(Z0) edge (Y0);
\path[<->, dashed] (X0) edge[bend left=50] (Y0);
\end{tikzpicture}
\caption{Identifiable}
\end{subfigure}
\caption{Write me}
\label{fig:ID_examples}
\end{wrapfigure}
\lipsum[1-2]
\end{document}