0

I have produced two figures using TikZ that currently consume one full page(each taking up a half of the page). I want to scale these images and place them side by side horizontally so that I can save up half a page. I tried using the subfloat environment, and somehow things are getting very messy. Can someone tell me how to do this? Here is my Tikz code:

\documentclass{report}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{subfig} 
\usepackage{verbatim}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{float}
\usepackage{xspace}
\usepackage{tikz}
\usepackage{subfloat}
\usetikzlibrary{shapes,arrows,shadows}
\usepackage{bm,times}
\usepackage{pgf}

\begin{document}

\begin{figure}

\begin{tikzpicture}


\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command

% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles used later

\tikzstyle{sensor}=[draw, fill=white!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{ann} = [above, text width=5em, text centered]
\tikzstyle{wa} = [sensor, text width=10em, fill=white!20, 
    minimum height=6em, rounded corners, drop shadow]
\tikzstyle{sc} = [sensor, text width=13em, fill=white!20, 
    minimum height=10em, rounded corners, drop shadow]

% Define distances for bordering
\def\blockdist{2.3}
\def\edgedist{2.5}

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-7.0,3.5) rectangle (-3.5, -3.5);           
  \coordinate [label=left:$C_3$] (A) at (-4.5,3.0);

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-1.0,3.5) rectangle (2.0, -3.5);           
  \coordinate [label=left:$C_2$] (A) at (0,3.0);

  \node (wa) [sensor]  {$CK$};
    \path (wa.west)+(-4.0,1.5) node (asr1) [sensor] {$CK$};
    \path (wa.west)+(-4.0,0.5) node (asr2)[sensor] {$CK$};
    \path (wa.west)+(-4.0,-1.0) node (dots)[ann] {$\vdots$}; 
    \path (wa.west)+(-4.0,-2.0) node (asr3)[sensor] {$CK$};    

    \path (wa.east)+(\blockdist,-1) node (c1) [sensor] {$C_1$};
    \path (c1.west)+(-1,-0.5) node (dots)[ann] {$\vdots$};  
    \path (wa.south)+(0,-2.0) node (c22)[sensor] {$CK$};  

    \path [draw, ->] (asr1.east) -- node [above] {$1$} 
        (wa.160) ;
    \path [draw, ->] (asr2.east) -- node [above] {$2$} 
        (wa.180);
    \path [draw, ->] (asr3.east) -- node [above] {$m$} 
        (wa.200);
    \path [draw, ->] (wa.east) -- node [above] {} 
        (c1.west);
    \path (c1.east) ++ (1,0) node (temp) { };
    \path [draw, ->] (c1) -- (temp);
    \path [draw, ->] (c22) -- (c1);            


     \path (c22.west) ++ (-1,0.4) node (temp2) { };
     \path [draw, ->] (temp2) -- (c22);
    \path (c22.west) ++ (-1,-0.4) node (temp3) { };
    \path [draw, ->] (temp3) -- (c22);
     \path (c22.west)++(-0.5,-0.25) node (dots1)[ann] {$\vdots$}; 


\end{tikzpicture}

\caption{\label{fig:in} A Figure}
\centering

\end{figure}



\begin{figure}

\centering
\begin{tikzpicture}


\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command

% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles used later

\tikzstyle{sensor}=[draw, fill=white!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{logic}=[draw, fill=white!20, text width=3em, 
    text centered, minimum height=1.5em,drop shadow]
\tikzstyle{ann} = [above, text width=5em, text centered]
\tikzstyle{wa} = [sensor, text width=10em, fill=white!20, 
    minimum height=6em, rounded corners, drop shadow]
\tikzstyle{sc} = [sensor, text width=13em, fill=white!20, 
    minimum height=10em, rounded corners, drop shadow]

% Define distances for bordering
\def\blockdist{2.0}
\def\edgedist{2.0}

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-1.0,3.0) rectangle (4.0, -4.5);           
  \coordinate [label=left:$C_2'$] (A) at (1.0,1.5);

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-5.0,3.0) rectangle (-2.5, -4.8);           
  \coordinate [label=left:$C_3'$] (A) at (-4.0, 2.5);

    \node (wa) [logic]  {$\land$};
    \path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$CK$};
    \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$CnK$};
    \path (wa.west)+(-3.2,-0.5) node (asr3) [sensor] {$CK$};
    \path (wa.west)+(-3.2,-1.5) node (dots)[ann] {$\vdots$}; 
    \path (wa.west)+(-3.2,-2.0) node (asr4)[sensor] {$CK$};    
    \path (wa.west)+(-3.2,-3.0) node (asr5)[sensor] {$CnK$};
    \path (wa.west)+(-3.2,-4.0) node (asr6) [sensor] {$CK$};


    \path (wa.east)+(\blockdist,0.5) node (lor) [sensor] {$\lor$};

    \path [draw, ->] (asr1.east) -- node [above] {$S_{1,0}$} 
        (wa.160) ;
    \path [draw, ->] (asr2.east) -- node [above] {$S_{1,1}$} 
        (wa.162);
    \path [draw, ->] (asr3.east) -- node [above] {$B_1$} 
        (wa.164);
    \path [draw, ->] (wa.east) -- node [above] {} 
        (lor.west);
    \path (wa.south)+(0,-1.3) node (dots)[ann] {$\vdots$}; 

%    \node (wa.south)+(0.0, -4.0) node (wa1) [logic] {$\land$};
%   \node (wa.south)+(0.0, -1.0) node (wa1) [logic] {$\land$};
 \node (wa.south)+(0.0, -2.0) node (wa1) [logic] {$\land$};
% \node (wa.south)+(0.0, -3.0) node (wa1) [logic] {$\land$};

   \path [draw, ->] (asr4.east) -- node [above] {$S_{m,0}$} 
        (wa1.180) ;
    \path [draw, ->] (asr5.east) -- node [above] {$S_{m,1}$} 
        (wa1.182);
    \path [draw, ->] (asr6.east) -- node [above] {$B_m$} 
        (wa1.184);
    \path [draw, ->] (wa1.east) -- node [below] {} 
        (lor.west);           

    \path (wa1.east)+(\blockdist, -1.5) node (lor1) [sensor] {$\lor$};
    \path (wa.east)+(\blockdist,-1.5) node (dots)[ann] {$\vdots$}; 

  \path (wa.east)+(4.5,-1.5) node (c1) [sensor] {$C_1$};

  \path (wa.east) + (6, -1.5) node (temp) { };
%  \path (lor1.west) ++ (-1,0) node (temp1) { };
 %   \path [draw, ->] (temp1) -- (lor1);
    \path (lor1.west)++(-0.5,-0.25) node (dots1)[ann] {$\vdots$}; 

     \path (lor1.west) ++ (-1,0.4) node (temp2) { };
     \path [draw, ->] (temp2) -- (lor1);
    \path (lor1.west) ++ (-1,-0.4) node (temp3) { };
    \path [draw, ->] (temp3) -- (lor1);


  \path [draw, ->] (lor1) -- (c1);
  \path [draw, ->] (c1)-- (temp);
    \path [draw, ->] (lor) -- (c1);
    \begin{pgfonlayer}{background}

    \path[fill=white!20,rounded corners, draw=black!50, dashed]
            (3,3) rectangle (-3,-3);           

    \end{pgfonlayer}


\end{tikzpicture}

\caption{\label{fig:collapse}Another Figure}

\end{figure}

\end{document}
  • This looks very similar to tex.stackexchange.com/q/19617/15925 – Andrew Swann Nov 28 '13 at 20:09
  • Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. – Herr K. Nov 29 '13 at 0:17
  • @KevinC I have a MWE now (though its embedded in a horrible way here! Don't know what I am doing wrong). – Nikhil Nov 29 '13 at 2:26
  • 1
    If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). – Herr K. Nov 29 '13 at 3:56
3

This may not be the solution you want, but it works. BTW, could you at least try to create a MWE which is minimal and working, but still has the problem.

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}

\usetikzlibrary{shadows}


\begin{document}


\begin{figure}[t]
\centering
\begin{tabular}{cc}
\begin{tikzpicture}[thick,scale=0.5,every node/.style={scale=0.5}]
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} 
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} 

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}


\tikzstyle{sensor}=[draw, fill=white!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{ann} = [above, text width=5em, text centered]
\tikzstyle{wa} = [sensor, text width=10em, fill=white!20, 
    minimum height=6em, rounded corners, drop shadow]
\tikzstyle{sc} = [sensor, text width=13em, fill=white!20, 
    minimum height=10em, rounded corners, drop shadow]


\def\blockdist{2.3}
\def\edgedist{2.5}

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-7.0,3.5) rectangle (-3.5, -3.5);           
  \coordinate [label=left:$C_3$] (A) at (-4.5,3.0);

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-1.0,3.5) rectangle (2.0, -3.5);           
  \coordinate [label=left:$C_2$] (A) at (0,3.0);

  \node (wa) [sensor]  {$CK$};
    \path (wa.west)+(-4.0,1.5) node (asr1) [sensor] {$CK$};
    \path (wa.west)+(-4.0,0.5) node (asr2)[sensor] {$CK$};
    \path (wa.west)+(-4.0,-1.0) node (dots)[ann] {$\vdots$}; 
    \path (wa.west)+(-4.0,-2.0) node (asr3)[sensor] {$CK$};    

    \path (wa.east)+(\blockdist,-1) node (c1) [sensor] {$C_1$};
    \path (c1.west)+(-1,-0.5) node (dots)[ann] {$\vdots$};  
    \path (wa.south)+(0,-2.0) node (c22)[sensor] {$CK$};  

    \path [draw, ->] (asr1.east) -- node [above] {$1$} 
        (wa.160) ;
    \path [draw, ->] (asr2.east) -- node [above] {$2$} 
        (wa.180);
    \path [draw, ->] (asr3.east) -- node [above] {$m$} 
        (wa.200);
    \path [draw, ->] (wa.east) -- node [above] {} 
        (c1.west);
    \path (c1.east) ++ (1,0) node (temp) { };
    \path [draw, ->] (c1) -- (temp);
    \path [draw, ->] (c22) -- (c1);            


    \path (c22.west) ++ (-1,0.4) node (temp2) { };
    \path [draw, ->] (temp2) -- (c22);
    \path (c22.west) ++ (-1,-0.4) node (temp3) { };
    \path [draw, ->] (temp3) -- (c22);
    \path (c22.west)++(-0.5,-0.25) node (dots1)[ann] {$\vdots$}; 
\end{tikzpicture}
&
\begin{tikzpicture}[thick,scale=0.5,every node/.style={scale=0.5}]

\newcommand{\mx}[1]{\mathbf{\bm{#1}}} 
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} 

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}


\tikzstyle{sensor}=[draw, fill=white!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{logic}=[draw, fill=white!20, text width=3em, 
    text centered, minimum height=1.5em,drop shadow]
\tikzstyle{ann} = [above, text width=5em, text centered]
\tikzstyle{wa} = [sensor, text width=10em, fill=white!20, 
    minimum height=6em, rounded corners, drop shadow]
\tikzstyle{sc} = [sensor, text width=13em, fill=white!20, 
    minimum height=10em, rounded corners, drop shadow]


\def\blockdist{2.0}
\def\edgedist{2.0}

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-1.5,2.0) rectangle (4.0, -4.5);           
  \coordinate [label=left:$C_2$] (A) at (1.0,1.5);

  \path[fill=white!20,rounded corners, draw=black!50, dashed]
           (-4.8,3.0) rectangle (-2.5, -4.8);           
  \coordinate [label=left:$C_3$] (A) at (-4.0, 2.5);

    \node (wa) [logic]  {$\land$};
    \path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$CK$};
    \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$CK$};
    \path (wa.west)+(-3.2,-0.5) node (asr3) [sensor] {$CK$};
    \path (wa.west)+(-3.2,-1.5) node (dots)[ann] {$\vdots$}; 
    \path (wa.west)+(-3.2,-2.0) node (asr4)[sensor] {$CK$};    
    \path (wa.west)+(-3.2,-3.0) node (asr5)[sensor] {$CK$};
    \path (wa.west)+(-3.2,-4.0) node (asr6) [sensor] {$CK$};


    \path (wa.east)+(\blockdist,0.5) node (lor) [sensor] {$\lor$};

    \path [draw, ->] (asr1.east) -- node [above] {$S_{1,0}$} 
        (wa.160) ;
    \path [draw, ->] (asr2.east) -- node [above] {$S_{1,1}$} 
        (wa.162);
    \path [draw, ->] (asr3.east) -- node [above] {$B_1$} 
        (wa.164);
    \path [draw, ->] (wa.east) -- node [above] {} 
        (lor.west);
    \path (wa.south)+(0,-1.3) node (dots)[ann] {$\vdots$}; 

 \path (wa.south)+(0.0, -2.0) node (wa1) [logic] {$\land$};

   \path [draw, ->] (asr4.east) -- node [above] {$S_{m,0}$} 
        (wa1.180) ;
    \path [draw, ->] (asr5.east) -- node [above] {$S_{m,1}$} 
        (wa1.182);
    \path [draw, ->] (asr6.east) -- node [above] {$B_m$} 
        (wa1.184);
    \path [draw, ->] (wa1.east) -- node [below] {} 
        (lor.west);           

    \path (wa1.east)+(\blockdist, -1.5) node (lor1) [sensor] {$\lor$};
    \path (wa.east)+(\blockdist,-1.5) node (dots)[ann] {$\vdots$}; 

  \path (wa.east)+(4.5,-1.5) node (c1) [sensor] {$C_1$};

  \path (wa.east) + (6, -1.5) node (temp) { };
    \path (lor1.west)++(-0.5,-0.25) node (dots1)[ann] {$\vdots$}; 

     \path (lor1.west) ++ (-1,0.4) node (temp2) { };
     \path [draw, ->] (temp2) -- (lor1);
    \path (lor1.west) ++ (-1,-0.4) node (temp3) { };
    \path [draw, ->] (temp3) -- (lor1);


  \path [draw, ->] (lor1) -- (c1);
  \path [draw, ->] (c1)-- (temp);
    \path [draw, ->] (lor) -- (c1);
    \begin{pgfonlayer}{background}

    \path[fill=white!20,rounded corners, draw=black!50, dashed]
            (3,3) rectangle (-3,-3);           

    \end{pgfonlayer}
\end{tikzpicture}
\\
A Figure&B Figure
\end{tabular}

\caption{\label{fig:fig1}}
\end{figure}

\end{document}
  • The output looks fine, yet I still get an error "Package TikZ error: A node must have a (possibly empty) label text" and it points to the line " \node (wa.south)+(0.0, -2.0) node (wa1) [logic] {$\land$};" Any idea how to fix this? – Nikhil Dec 1 '13 at 7:49
  • 1
    change \node to \path – John Kormylo Dec 1 '13 at 16:45
1

Your code is far away to be MWE and it also has some errors. So it is difficult to see, what is the problem. From the MWE below you can see, that with proper use of subfloats from subfig package you obtain nice figure on half of page:

\documentclass{article}
    \usepackage{caption,subfig}
    \usepackage{tikz}

\begin{document}
    \begin{figure}\centering
\subfloat[figure A  \label{fig:in}]%

\begin{tikzpicture}[thick,scale=0.5,every node/.style={scale=0.5}]
\node[draw,minimum height=\textheight, minimum width=\textwidth]
     {without scaling this  is full page picture A};
\end{tikzpicture}
}
\subfloat[figure B  \label{fig:out}]%
{
\begin{tikzpicture}[thick,scale=0.5,every node/.style={scale=0.5}]
\node[draw,minimum height=\textheight, minimum width=\textwidth, align=flush center]
     {without scaling this is full page picture B\\
      instead of this simple rectangle, there you put tikz code of your poicture};
\end{tikzpicture}
}
\caption{title of my figure}
\label{fig:fig1}
    \end{figure}
\end{document}

If you like to have more space between subfigures, just adjust scaling factor on smaller value as 0.5 and put between them \hfil or \hfill.

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.