我使用 TikZ 制作了两个图形,它们目前占用了一整页(每个图形占用了半页)。我想缩放这些图像并将它们水平并排放置,这样我就可以节省半页。我尝试使用 subfloat 环境,但不知何故事情变得非常混乱。有人能告诉我怎么做吗?这是我的 Tikz 代码:
\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}
答案1
这可能不是您想要的解决方案,但它确实有效。顺便说一句,您至少可以尝试创建一个最小且可以工作但仍然存在问题的 MWE。
\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}
答案2
您的代码远非 MWE,而且也有一些错误。因此很难看出问题所在。从下面的 MWE 中您可以看到,通过正确使用 subfig 包中的子浮点数,您可以在一半页面上获得漂亮的图形:
\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}
如果您希望子图之间有更多空间,只需将缩放因子调整为较小的值 0.5 并放置在它们之间\hfil
或\hfill
。