![独立文档类中的子图垂直堆叠](https://linux22.com/image/435378/%E7%8B%AC%E7%AB%8B%E6%96%87%E6%A1%A3%E7%B1%BB%E4%B8%AD%E7%9A%84%E5%AD%90%E5%9B%BE%E5%9E%82%E7%9B%B4%E5%A0%86%E5%8F%A0.png)
我有一个 tikz 绘图,我想将其导出为 PDF。\documentclass{standalone}
允许将 PDF 裁剪为绘图的大小。但是,子图随后会水平堆叠。如何才能垂直堆叠子图\documentclass{standalone}
?
我的 MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shapes,shadows,positioning}
\usetikzlibrary{backgrounds}
\tikzstyle{class} = [rectangle, rounded corners, minimum width=1cm, minimum height=1cm,text centered, draw=black, text = black]
\tikzstyle{process} = [rectangle, rounded corners, minimum width=1cm, minimum height=0.0cm,text centered, draw=white, text = black]
\tikzstyle{io} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white]
\tikzstyle{arrow} = [thick,->,>=stealth, color=black]
\tikzstyle{container} = [draw, rectangle, dashed, rounded corners, minimum height = 1.6cm, minimum width=1.55cm]
\tikzstyle{note} = [rectangle, dashed, draw, fill=white, text centered, rounded corners, minimum height=1.5cm, draw=black]
\usepackage{subfigure}
\renewcommand{\thesubfigure}{(\Alph{subfigure})}
\begin{document}
\begin{figure}[h!]
\centering
\subfigure[Caption for sub figure A.]{
\begin{tikzpicture}[node distance = 3.5cm]
\node(MSa)[class]{MS};
\node(trans)[process, right of = MSa]{$P^{\left(\text{\textit{trans}}\right)}$};
\node(MSb)[class, right of = trans]{MS+1};
\node(MSc)[class, below of = MSa, yshift = 1.8cm]{MS};
\draw[arrow](MSa.east) -- node[above, scale = 0.8, align=left]{$U(T^{\uparrow}_{min},T^{\uparrow}_{max})$} (trans.west);
\draw[arrow](trans.east) -- (MSb.west);
\draw[arrow](trans.south) |- (MSc.east);
\label{fig:MS dynamics prg}
\end{tikzpicture}}
\subfigure[Caption for sub figure B]{
\begin{tikzpicture}[node distance = 3.5cm]
\node(MSa)[class]{MS};
\node(cure)[process, right of = MSa]{$P^{\left(\text{\textit{cure}}\right)}$};
\node(MSb)[class, right of = cure]{MS-1};
\draw[arrow]([yshift = 0.1cm]MSa.east) -- ([yshift = 0.1cm]cure.west);
\draw[arrow](cure.east) -- node[above, scale = 0.8, align=left]{$U(T^{\downarrow}_{min},T^{\downarrow}_{max})$} (MSb.west);
\draw[arrow]([yshift = -0.1cm]cure.west) -- ([yshift = -0.1cm]MSa.east);
\label{fig:MS dynamics reg}
\end{tikzpicture}}
\end{figure}
\end{document}
答案1
如果您想要一个独立文件,我不明白使用figure
带标题的环境有什么用subfigure
。事实上,您的代码带有standalone
和figure
无法编译。
在下面的解决方案中,我使用tabular
将两个图形一个叠在另一个之上。
\documentclass{standalone}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shapes,shadows,positioning}
\usetikzlibrary{backgrounds}
\tikzstyle{class} = [rectangle, rounded corners, minimum width=1cm, minimum height=1cm,text centered, draw=black, text = black]
\tikzstyle{process} = [rectangle, rounded corners, minimum width=1cm, minimum height=0.0cm,text centered, draw=white, text = black]
\tikzstyle{io} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white]
\tikzstyle{arrow} = [thick,->,>=stealth, color=black]
\tikzstyle{container} = [draw, rectangle, dashed, rounded corners, minimum height = 1.6cm, minimum width=1.55cm]
\tikzstyle{note} = [rectangle, dashed, draw, fill=white, text centered, rounded corners, minimum height=1.5cm, draw=black]
\usepackage{subfigure}
\renewcommand{\thesubfigure}{(\Alph{subfigure})}
\begin{document}
%\begin{figure}[h!]
% \centering
\begin{tabular}{c}
% \subfigure[Caption for sub figure A.]{
\begin{tikzpicture}[node distance = 3.5cm]
\node(MSa)[class]{MS};
\node(trans)[process, right of = MSa]{$P^{\left(\text{\textit{trans}}\right)}$};
\node(MSb)[class, right of = trans]{MS+1};
\node(MSc)[class, below of = MSa, yshift = 1.8cm]{MS};
\draw[arrow](MSa.east) -- node[above, scale = 0.8, align=left]{$U(T^{\uparrow}_{min},T^{\uparrow}_{max})$} (trans.west);
\draw[arrow](trans.east) -- (MSb.west);
\draw[arrow](trans.south) |- (MSc.east);
\label{fig:MS dynamics prg}
\end{tikzpicture}
% }
\\
% \subfigure[Caption for sub figure B]{
\begin{tikzpicture}[node distance = 3.5cm]
\node(MSab)[class]{MS};
\node(cure)[process, right of = MSab]{$P^{\left(\text{\textit{cure}}\right)}$};
\node(MSbb)[class, right of = cure]{MS-1};
\draw[arrow]([yshift = 0.1cm]MSab.east) -- ([yshift = 0.1cm]cure.west);
\draw[arrow](cure.east) -- node[above, scale = 0.8, align=left]{$U(T^{\downarrow}_{min},T^{\downarrow}_{max})$} (MSbb.west);
\draw[arrow]([yshift = -0.1cm]cure.west) -- ([yshift = -0.1cm]MSab.east);
\label{fig:MS dynamics reg}
\end{tikzpicture}
% }
\end{tabular}
%\end{figure}
\end{document}
答案2
您的问题可以通过向文档类添加varwidth
选项来解决:standalone
\documentclass[%border=3mm,
varwidth] % <---
{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, quotes}
\tikzset{
arrow/.style = {thick,-stealth},
lbl/.style = {font=\footnotesize, above},
class/.style = {rectangle, draw, rounded corners, minimum size=1cm, align=center},
process/.style = {class, draw=none, minimum size=1ex},
io/.style = {class, minimum width=3cm, },
container/.style = {class, dashed, minimum sized=1.6cm},
note/.style = {container},
every edge/.style = {draw, arrow},
every edge quotes/.style = {auto, font=\footnotesize}
}
\usepackage{subfigure}
\renewcommand{\thesubfigure}{(\Alph{subfigure})}
\begin{document}
\begin{figure}
\subfigure[Caption for sub figure A. \label{fig:MS dynamics prg}]{
\begin{tikzpicture}[node distance = 22mm]
\node (MSa) [class]{MS};
\node (trans)[process, right=of MSa] {$P^{\text{trans}}$};
\node (MSb) [class, right=of trans] {MS+1};
\node (MSc) [class, below=of MSa, yshift = 1.8cm]{MS};
\draw (MSa) edge ["${U(T^{\uparrow}_{\min},T^{\uparrow}_{\max})}$"] (trans)
(trans) edge (MSb);
\draw[arrow] (trans) |- (MSc);
\end{tikzpicture}}
\bigskip
\subfigure[Caption for sub figure B \label{fig:MS dynamics reg}]{
\begin{tikzpicture}[node distance = 22mm]
\node (MSab) [class]{MS};
\node (cure) [process, right=of MSab]{$P^{(\text{cure})}$};
\node (MSbb) [class, right=of cure]{MS-1};
\draw ([yshift= 1mm] MSab.east) edge ([yshift = 0.1cm]cure.west)
(cure) edge ["${U(T^{\uparrow}_{\min},T^{\uparrow}_{\max})}$"] (MSbb)
([yshift=-1mm] cure.west) edge ([yshift = -0.1cm]MSab.east);
\label{fig:MS dynamics reg}
\end{tikzpicture}}
\end{figure}
\end{document}
有趣的是,在这种情况下,仅弃用subfigure
水平居中子标题包。新包subfig
将subcation
标题推到图像左边框。例如:
\documentclass[%border=3mm,
varwidth % <---
]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, quotes}
\tikzset{
arrow/.style = {thick,-stealth},
lbl/.style = {font=\footnotesize, above},
class/.style = {rectangle, draw, rounded corners, minimum size=1cm, align=center},
process/.style = {class, draw=none, minimum size=1ex},
io/.style = {class, minimum width=3cm, },
container/.style = {class, dashed, minimum sized=1.6cm},
note/.style = {container},
every edge/.style = {draw, arrow},
every edge quotes/.style = {auto, font=\footnotesize}
}
\usepackage[skip=1ex, justification=centering]{subcaption}
\renewcommand{\thesubfigure}{(\Alph{subfigure})}
\begin{document}
\begin{figure}
\subfloat[Caption for sub figure A \label{fig:MS dynamics prg}]{
\begin{tikzpicture}[node distance = 22mm]
\node (MSa) [class]{MS};
\node (trans)[process, right=of MSa] {$P^{\text{trans}}$};
\node (MSb) [class, right=of trans] {MS+1};
\node (MSc) [class, below=of MSa, yshift = 1.8cm]{MS};
\draw (MSa) edge ["${U(T^{\uparrow}_{\min},T^{\uparrow}_{\max})}$"] (trans)
(trans) edge (MSb);
\draw[arrow] (trans) |- (MSc);
\end{tikzpicture}}
\bigskip
\subfloat[Caption for sub figure B \label{fig:MS dynamics reg}]{
\begin{tikzpicture}[node distance = 22mm]
\node (MSab) [class]{MS};
\node (cure) [process, right=of MSab]{$P^{(\text{cure})}$};
\node (MSbb) [class, right=of cure]{MS-1};
\draw ([yshift= 1mm] MSab.east) edge ([yshift = 0.1cm]cure.west)
(cure) edge ["${U(T^{\uparrow}_{\min},T^{\uparrow}_{\max})}$"] (MSbb)
([yshift=-1mm] cure.west) edge ([yshift = -0.1cm]MSab.east);
\label{fig:MS dynamics reg}
\end{tikzpicture}}
\end{figure}
\end{document}
在这两种情况下,MWE 中的代码都是索引的更正书写,并且也因此而缩短。