6

I have four different tikzpictures merged in one single figure by means of the subcaption package and the \subfigure environment. However, the figures have different horizontal lengths, so I don't get a proper vertical alignment. Immagine

Instead of this, I would like to have the center of each box vertically aligned with the center of the other boxes and with the subcaptions, i.e. (a),(b)...

I wouldn't mind if something had to be rescaled (to fit the linewidth), but please note that each subfigure should be rescaled accordingly, in order for all the boxes to be of the same size.

Here is my code:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
  \begin{subfigure}{\linewidth}
    \centering
    \begin{tikzpicture}[>=latex]
      \node (a) [] {$c_k\delta_{\Delta}(t-k\Delta)+c_j\delta_{\Delta}(t-j\Delta)$};
      \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [right=of a] {\texttt{SISO-L}};
      \node (c) [right=of b] {$c_kh_{k\Delta}(t)+c_jh_{j\Delta}(t)$};
      \path [->,thick] (a) edge (b)
                     (b) edge (c);
    \end{tikzpicture}
  \caption{}
\label{fig:}
\end{subfigure}\\[.5cm]
\begin{subfigure}{\linewidth}
  \centering
  \begin{tikzpicture}[>=latex]
    \node (a) [] {$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)\delta_{\Delta}(t-k\Delta)\Delta$};
    \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [right=of a] {\texttt{SISO-L}};
    \node (c) [right=of b] {$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)h_{k\Delta}(t)$};
    \path [->,thick] (a) edge (b)
                     (b) edge (c);
  \end{tikzpicture}
\caption{}
\label{fig:}
\end{subfigure}\\[.5cm]
\begin{subfigure}{\linewidth}
  \centering
  \begin{tikzpicture}[>=latex]
      \node (a) [] {$\delta(t-\tau)$};
    \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [right=of a] {\texttt{SISO-L}};
    \node (c) [right=of b] {$h_{\tau}(t)$};
    \path [->,thick] (a) edge (b)
                     (b) edge (c);
  \end{tikzpicture}
\caption{}
\label{fig:}
\end{subfigure}\\[.5cm]
\begin{subfigure}{\linewidth}
\centering
  \begin{tikzpicture}[>=latex]
    \node (a) [] {$\displaystyle u(t)=\int_{-\infty}^{\infty}u(\tau)\delta(t-\tau)\,\mathrm{d}\tau$};
    \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [right=of a] {\texttt{SISO-L}};
    \node (c) [right=of b] {$\displaystyle y(t)=\int_{-\infty}^{\infty}u(\tau)h_{\tau}(t)\,\mathrm{d}\tau$};
    \path [->,thick] (a) edge (b)
                     (b) edge (c);
  \end{tikzpicture}
\caption{}
\label{fig:}
\end{subfigure}
\caption{}
\label{fig:}
\end{figure}
\end{document}

Thanks in advance.

3
  • Why not draw everything inside the same tikz picture, using nodes?
    – Sigur
    Jan 17, 2014 at 23:08
  • @Sigur: thank you for your fast answer. I thought of that, but I need the "subcaptions"; is there a way to do as you suggest while conserving the multiple subcaptions?
    – Pier Paolo
    Jan 17, 2014 at 23:11
  • You can fake the subcaptions using another nodes below of the boxes.
    – Sigur
    Jan 17, 2014 at 23:12

3 Answers 3

1

Another solution (based on the OP code): This one only works if the \linewidth is large enough so that the figure does not produce overfull.

What I did was to make sure that all chains have the same width on the left and on the right of the central nodes.

So I inserted (on four figures) some fake nodes (remove the draw after) with constant width.

\node[minimum width=5cm,draw] (lfake) [left= of b]{};
\node[minimum width=5cm,draw] (rfake) [right=of b]{};

enter image description here

\begin{tikzpicture}[>=latex]
\node (a)  {$c_k\delta_{\Delta}(t-k\Delta)+c_j\delta_{\Delta}(t-j\Delta)$};
\node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [right=of a] {\texttt{SISO-L}};
\node (c) [right=of b] {$c_kh_{k\Delta}(t)+c_jh_{j\Delta}(t)$};
\node[minimum width=5cm,draw] (lfake) [left=of b]{};
\node[minimum width=5cm,draw] (rfake) [right=of b]{};
\path [->,thick] (a) edge (b) (b) edge (c);
\end{tikzpicture}
1
  • I had to manually specify the exact width of the fake nodes, but it turned out as I had imagined. Thanks.
    – Pier Paolo
    Jan 18, 2014 at 10:21
4

You have to discover how to adjust the vertical distance between the boxes and the captions (both are nodes) (for example, node (a) and its caption node (acap)).

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{graphicx}
\usepackage{lipsum} %% dummy text
\begin{document}

\lipsum*[2]
\begin{figure}[h]
\begin{tikzpicture}[>=latex]
 \node[draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (a)  {\texttt{SISO-L}};
 \node (al) [left=of a] {$c_k\delta_{\Delta}(t-k\Delta)+c_j\delta_{\Delta}(t-j\Delta)$};
 \node (ar) [right=of a] {$c_kh_{k\Delta}(t)+c_jh_{j\Delta}(t)$};
 \node (acap) [below=5pt of a] {(a)};
 \path [->,thick] (al) edge (a) (a) edge (ar);
%%
 \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) [below=1em of acap] {\texttt{SISO-L}};
 \node (bl) [left=of b] {$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)\delta_{\Delta}(t-k\Delta)\Delta$};
 \node (br) [right=of b] {$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)h_{k\Delta}(t)$};
 \node (bcap) [below=5pt of b] {(b)};
 \path [->,thick] (bl) edge (b) (b) edge (br);
%%
 \node [draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (c)  [below=1em of bcap] {\texttt{SISO-L}};
 \node (cl) [left=of c] {$\delta(t-\tau)$};
 \node (cr) [right=of c] {$h_{\tau}(t)$};
 \node (ccap) [below=5pt of c] {(c)};
 \path [->,thick] (cl) edge (c) (c) edge (cr);
\end{tikzpicture}
\caption{caption title}\label{key}
\end{figure}

Figure~\ref{key}(a) shows that\ldots 
\end{document}

enter image description here

2
  • spacing between nodes can be adjusted with: \node (bcap) [below=.5cm of b] {(b)}, but my problem is, sorry if I insist, that I need real captions for later cross-references
    – Pier Paolo
    Jan 17, 2014 at 23:33
  • Thanks. Edited. I agree with you about the captions but if those 3 diagrams will be always in that order you will not have problem to cite them using the label of the total figure, as I did.
    – Sigur
    Jan 17, 2014 at 23:50
1

The idea is similar to the one proposed by Sigur in his "another solution". If every subfigure occupies the whole text line (\linewidth) and this space is divided in three fragments where left and right ones have equal length, then the central fragment will be centered. Then all subfigures will present their central part vertically aligned.

Next code uses X columns from tabularx package to automatically compute left and right fragments width, leaving the central one having its natural width. TiKZ is only used in central columns, while left and right ones are aligned with \raggedright and \raggedleft.

There is no need to manually compute any width.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\usepackage{tabularx}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\raggedright\arraybackslash}X}
\usepackage{lipsum}

\begin{document}

\begin{figure}
\setlength{\tabcolsep}{2pt}
\begin{subfigure}{\linewidth}
\begin{tabularx}{\linewidth}{YcZ}
$c_k\delta_{\Delta}(t-k\Delta)+c_j\delta_{\Delta}(t-j\Delta)$
&
\tikz[baseline=(b.base)]{ \draw[->,thick] (0,0)--++(0:.5cm) node [anchor=west,draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) {\texttt{SISO-L}}; \draw[->,thick] (b.east)--++(0:.5cm);}
&
$c_kh_{k\Delta}(t)+c_jh_{j\Delta}(t)$ \tabularnewline
\end{tabularx}
\caption{This is the caption for the first subfigure}
\end{subfigure}

\begin{subfigure}{\linewidth}
\begin{tabularx}{\linewidth}{YcZ}
$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)\delta_{\Delta}(t-k\Delta)\Delta$
&
\tikz[baseline=(b.base)]{ \draw[->,thick] (0,0)--++(0:.5cm) node [anchor=west,draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) {\texttt{SISO-L}}; \draw[->,thick] (b.east)--++(0:.5cm);}
&
$\displaystyle \sum_{k=-\infty}^{\infty}u(k\Delta)h_{k\Delta}(t)$ \tabularnewline
\end{tabularx}
\caption{This is the caption for the second subfigure}
\end{subfigure}

\begin{subfigure}{\linewidth}
\begin{tabularx}{\linewidth}{YcZ}
$\delta(t-\tau)$
&
\tikz[baseline=(b.base)]{ \draw[->,thick] (0,0)--++(0:.5cm) node [anchor=west,draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) {\texttt{SISO-L}}; \draw[->,thick] (b.east)--++(0:.5cm);}
&
$h_{\tau}(t)$ \tabularnewline
\end{tabularx}
\caption{This is the caption for the third subfigure}
\end{subfigure}

\begin{subfigure}{\linewidth}
\begin{tabularx}{\linewidth}{YcZ}
$\displaystyle u(t)=\int_{-\infty}^{\infty}u(\tau)\delta(t-\tau)\,\mathrm{d}\tau$
&
\tikz[baseline=(b.base)]{ \draw[->,thick] (0,0)--++(0:.5cm) node [anchor=west,draw,thick,rectangle,minimum width=2cm,minimum height=1cm] (b) {\texttt{SISO-L}}; \draw[->,thick] (b.east)--++(0:.5cm);}
&
$\displaystyle y(t)=\int_{-\infty}^{\infty}u(\tau)h_{\tau}(t)\,\mathrm{d}\tau$ \tabularnewline
\end{tabularx}
\caption{This is the caption for the fourth subfigure}
\end{subfigure}

\caption{This is the main caption}
\end{figure}

\lipsum
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .