Minipage:无法在页面顶部获取图片

Minipage:无法在页面顶部获取图片

我试图将这些内容合并到一页中的流程图中。这是我目前得到的结果,但我认为做得不是很好。有什么建议可以让我如何将流程图放在页面顶部,并将它们整齐地放在一起,并带有自己的标题?

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shapes.multipart}
\usetikzlibrary{calc}
\usepackage{graphicx}


\begin{document}

\tikzset{
offpageconnector/.style = {draw (1,0) -- (0,1) -- (-1,0) -- (0,-1) -- cycle, fill=orange!20},
decision/.style = {diamond, draw, fill=orange!20, 
  text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style = {rectangle, draw, fill=blue!20, 
  text width=5em, text centered, minimum height=1cm},
terminator/.style = {rectangle, rounded corners, draw, fill=blue!20, 
  text width=5em, text centered, minimum height=1cm, node distance=3cm},
line/.style = {draw, -latex'},
cloud/.style = {draw, ellipse,fill=red!20, node distance=1.5cm,
  minimum height=2em},
subroutine/.style = {draw,rectangle split, rectangle split horizontal,
  rectangle split parts=3,minimum height=1cm,
  rectangle split part fill={green!50}},
connector/.style = {draw,circle,node distance=3cm,fill=purple!20},
data/.style = {draw, trapezium,trapezium left angle=70,trapezium right angle=-70,minimum height=1cm,node distance=3cm,fill=olive!20},
cloud/.style = {draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em}}
 
\begin{figure}[!hbt]
   \begin{minipage}[b]{0.4\textwidth}
      
      \begin{center}
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [cloud] (start) {Start};
    \node [block, below of=start,node distance=2cm] (init) {Init};
    \node [block, below of=init,node distance=2cm] (1ebyteop) {$1^{e}$ byte ophalen};
    \node [decision,below of=1ebyteop,node distance=2cm] (contreof) {EOF?};
    \node [terminator, right of=contreof] (end1) {END};
    \node [block, below of=contreof] (2ebyteop) {$2^{e}$ byte ophalen};
    \node [decision,below of=2ebyteop,node distance=2cm] (contreof2) {EOF?};
    \node [terminator, right of=contreof2] (end2) {END};
    \node [subroutine, below of=contreof2, node distance=2cm] (sub1) {\nodepart{two} SUB1};
    \node [subroutine, below of=sub1, node distance=2cm] (sub2) {\nodepart{two} SUB2};
    
    
    
    % Draw edges
    \path [line] (start) -- (init);
    \path [line] (init) -- (1ebyteop);
    \path [line] (1ebyteop) -- (contreof);
    \path [line] (contreof) -- node {yes} (end1);
    \path [line] (contreof) -- node {no}(2ebyteop);
    \path [line] (2ebyteop) -- (contreof2);
    \path [line] (contreof2) -- node {yes} (end2);
    \path [line] (contreof2) -- node {no}(sub1);
    \path [line] (sub1) -- (sub2);
    \path [line] (sub2) |- ($(sub2.south west) - (0.7,0.7)$) |- (1ebyteop);
  
\end{tikzpicture}
\end{center}
      \caption{Flow1}
      \label{fig:flow1}
   \end{minipage}
   \hfill
   \begin{minipage}[b]{0.4\textwidth}
    
\noindent\resizebox{0.25\textheight}{!}{
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [connector,text width=1cm] (letter) {LET};
    \node [subroutine, below of=letter, node distance=2cm] (sub31) {\nodepart{two} SUB3};
    \node [decision,below of=sub31,node distance=2cm] (@) {@?};
    \node [connector, right of=@,text width=1cm] (fout1) {FOUT};
    \node [subroutine, below of=@, node distance=2cm] (sub32) {\nodepart{two} SUB3};
    \node [decision,below of=sub32,node distance=2cm] (leesteken) {Leesteken?};
    \node [connector, right of=leesteken,text width=1cm] (fout2) {FOUT};
    \node [subroutine, below of=leesteken, node distance=2cm] (sub33) {\nodepart{two} SUB3};
    \node [decision,below of=sub33,node distance=2cm] (atotf) {A-F?};
    \node [connector, right of=atotf,text width=1cm] (fout3) {FOUT};
    \node [block, below of=atotf,node distance=2cm] (vorm0x0h) {In vorm 0x0H};
    \node [block, below of=vorm0x0h,node distance=2cm] (add09) {ADD 0x09};
    \node [decision,below of=add09,node distance=2cm] (1eof2e) {$1^e$ of $2^e$ byte?};
    \node [block, right of=1eof2e,node distance=3cm] (rotate) {4 maal rotate};
    \node [block, below of=1eof2e,node distance=2cm] (inr3) {A in R3};
    \node [block, below of=rotate,node distance=2cm] (inr2) {A in R2};
    \node [block, below of=inr3,node distance=2cm] (incr1) {INC R1};
    \node [decision,below of=incr1,node distance=2cm] (1eof2e2) {$1^e$ of $2^e$ byte?};
    \node [connector, right of=1eof2e2,node distance=3cm,text width=1cm] (second) {SEC};
    \node [block, below of=1eof2e2,node distance=2cm] (ret) {RET};
    % Draw edges
    \path [line] (letter) -- (sub31);
    \path [line] (sub31) -- (@);
    \path [line] (@) -- node {yes} (fout1);
    \path [line] (@) -- node {no}(sub32);
    \path [line] (sub32) -- (leesteken);
    \path [line] (leesteken) -- node {yes} (fout2);
    \path [line] (leesteken) -- node {no}(sub33);
    \path [line] (sub33) -- (atotf);
    \path [line] (atotf) -- node {yes} (fout3);
    \path [line] (atotf) -- node {no}(vorm0x0h);
    \path [line] (vorm0x0h) -- (add09);
    \path [line] (add09) -- (1eof2e);
    \path [line] (1eof2e) -- node {1e} (rotate);
    \path [line] (1eof2e) -- node {2e}(inr3);
    \path [line] (rotate) -- (inr2);
    \path [line] (inr3) -- (incr1);
    \path [line] (incr1) -- (1eof2e2);
    \path [line] (add09) -- (1eof2e);
    \path [line] (inr2) |- ($(incr1.south east) - (1,0.1)$);
    \path [line] (1eof2e2) -- (ret);
    \path [line] (1eof2e2) -- (second);
  
\end{tikzpicture}
}     
      \caption{Flow2}
      \label{fig:flow2}
   \end{minipage}
\end{figure}    


\end{document}

答案1

你可以把所有东西都向上移动,例如

\begin{figure}[!hbpt]
\vspace{-2in}
   \begin{minipage}[b]{0.4\textwidth}\centering
\begin{tikzpicture}[node distance = 2cm, auto]
...

但是垂直尺寸大于页面物理顶部和页码之间的距离,因此您要么需要使用\thispagestyle{empty}删除页码,要么通过包装它\resizebox或使用 tikz 自己的缩放机制使图形变小。

请注意,我使用\centering而不是,\begin{center}因为它占用的垂直空间较少。

相关内容