2

I have a tikz drawing I want to export as a PDF. \documentclass{standalone} allows for the PDF to be cropped to the size of the drawing. However, the subfigures are then horizontally stacked. What can be done to vertically stack the subfigures with \documentclass{standalone}?

My 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}

altfi_SU
  • 131

2 Answers2

2

If you want and independent file, I don't understand the use of a figure environment with subfigure captions. In fact your code with standalone and figure doesn't compile.

In following solution, I've used a tabular to place both figures one above the other.

\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}

enter image description here

Ignasi
  • 136,588
1

Your problem can be solved by adding varwidth option to standalone document class:

\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}

enter image description here

Interestingly, that in this case only deprecate package subfigure center sub caption horizontally. New packages subfig and subcation push caption to the left image border. For example:

\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}

enter image description here

In both cases the code in your MWE is corrected writing of indices and by this shortened too.

Zarko
  • 296,517