15

I use subfig to show an array of tikz figures. Unfortunately these figures are sometimes of different height, so they don't show up properly aligned:

enter image description here

I'd like to see all nodes on the same line. I'm new to TikZ, so I'm wondering if it is possible to give all figures a minimum height. I tried to set a bounding box using \useasboundingbox (0,0) rectangle (5,2); but it was difficult for me to estimate the correct values. Is there a way to calculate that, or is it possible to render an invisible phantom edge (with label) that gives the figure a) the same height as figure b)? Or is there a way to do the alignment on subfig's side?

Below is a MWE:

\documentclass{article}
\usepackage{subfig}
\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{arrows}
\tikzstyle{state}=[circle,thick,draw=black!75,fill=black!20,minimum size=6mm, text=black]

\begin{document}


\begin{figure}
\centering
\subfloat[In-only]{\label{fig:in}
   \begin{tikzpicture}[node distance=2.8cm, bend angle=35,auto]
      \node [state] (v1) at (1,0) {$D$};
      \node [state] (v2) at (4,0) {$N$};
      \draw (v1) edge [<-, bend left] node {$M_\text{in}$} (v2);
    \end{tikzpicture}
}
\quad
\subfloat[In-only]{\label{fig:in}
   \begin{tikzpicture}[node distance=2.8cm, bend angle=35,auto]
      \node [state] (v1) at (1,0) {$D$};
      \node [state] (v2) at (4,0) {$N$};
      \draw (v1) edge [<-, bend left] node {$M_\text{in}$} (v2);
      \draw (v1) edge [->, bend right] node {$M_\text{out}$} (v2);
    \end{tikzpicture}
}

\end{figure}
\end{document}
  • A possible hack-ish solution which also requires a little bit of adjustment is adding baseline=1cm to the first tikzpicture options. I don't know too much about subfig but you can also consider subcaption package or using minipages :) See further vertical alignment with subfig and subcaption vs. subfig – percusse Dec 15 '11 at 13:35
16

For each TikZ picture, set the baseline option and refer to the node you would like to use for the alignment:

\begin{tikzpicture}[baseline=(nodename.base),...]
  • Awesome, I didn't expect it to be so easy. Thanks! – vanto Dec 15 '11 at 14:01
  • Here baseline=(v1.base) because v1 and v2 are aligned vertically in each picture. – Alain Matthes Dec 15 '11 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.