我从上个月开始就一直这样做。我想使用
\documentclass[a4paper,11pt]{report}
但是如果我使用上述配置(我想要使用)流程图不会显示在一页中,我该如何解决这个问题?请帮我完成流程图。
1) 我该如何为此写标题?
2)还有其他简单的乳胶包可以做到这一点吗?
代码
\documentclass[a4paper,10pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains,calc}
\begin{document}
% Define block styles
\tikzset{
desicion/.style={
diamond,
draw, thick,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw, thick,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
},
line/.style={>=latex,->,thick}
}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=3cm,row sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
|[block]| {Start} & & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by } & & \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by} & & \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by} & |[block]| {$A=c^2$ \\ $A=b^2$} & |[block]| {Globsl \\ Optimal \\ Configuration} \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by} & & \\
|[desicion]| {Locally optimal} & & |[block]| {Stop} \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by} & |[desicion]| {Locally optimal} & \\
};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)] in {1,2,3,4,5,6,7,8,9}{
\path [line] (m-\f-1) edge (m-\t-1);
}
\path [line,red] (m-10-1) edge (m-10-2);
\draw[line,red] (m-10-2) -- (m-6-2) node[pos=0.3,right,text=black]{ Yes, Pass (a,c)};
\draw [line] (m-6-2) --node[midway,below,text=black]{Yes, Pass (a,c)} node[midway,above,text=black]{Step 6} (m-6-3);
\path [line,red] (m-6-3) edge (m-9-3);
\draw [line,red] (m-10-2) -| (m-9-3);
\foreach \f/\l[evaluate=\f as \t using int(\f+1)] in {3/a,5/b,7/c,9/d}{
\draw [line,red] (m-\f-1.east) --node[midway,above,text=black]{Yes, Pass (a,c)} ++ (2.5cm,0)coordinate[](\l);
\draw [line,red] (m-\f-1.east) -| ([xshift=1.5cm]m-\t-1.north);
}
\node[xshift=-2cm] at (m-3-1){Step 1(4)};
\node[xshift=-2cm] at (m-5-1){Step 2 (7)};
\node[xshift=-2cm] at (m-7-1){Step 3 (9)};
\node[xshift=-2cm] at (m-9-1){Step 4 (3)};
\node[xshift=-2cm,above] at (m-10-2){Step 5};
\draw [>=latex,-,red,thick] (a) --(d);
\draw [line,red] ($(a)!0.5!(d)$) -- (m-6-2);
\end{tikzpicture}
\end{document}
答案1
您可以使用adjustbox
包及其adjustbox
环境并获取标题,使用figure
环境:
\begin{figure}[htbp]
\begin{adjustbox}{max height=0.9\textheight,center} %% adjust max height
your tikz code
\end{adjustbox}
\caption{This is my flow chart}
\end{figure}
完整代码:
\documentclass[a4paper,10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains,calc}
\usepackage{adjustbox}
\begin{document}
% Define block styles
\tikzset{
desicion/.style={
diamond,
draw, thick,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw, thick,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
},
line/.style={>=latex,->,thick}
}
\begin{figure}[htbp]
\begin{adjustbox}{max height=0.9\textheight,center} %% adjust max height
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=3cm,row sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
|[block]| {Start} & & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by } & & \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by} & & \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by} & |[block]| {$A=c^2$ \\ $A=b^2$} & |[block]| {Globsl \\ Optimal \\ Configuration} \\
|[desicion]| {Locally optimal} & & \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by} & & \\
|[desicion]| {Locally optimal} & & |[block]| {Stop} \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by} & |[desicion]| {Locally optimal} & \\
};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)] in {1,2,3,4,5,6,7,8,9}{
\path [line] (m-\f-1) edge (m-\t-1);
}
\path [line,red] (m-10-1) edge (m-10-2);
\draw[line,red] (m-10-2) -- (m-6-2) node[pos=0.3,right,text=black]{ Yes, Pass (a,c)};
\draw [line] (m-6-2) --node[midway,below,text=black]{Yes, Pass (a,c)} node[midway,above,text=black]{Step 6} (m-6-3);
\path [line,red] (m-6-3) edge (m-9-3);
\draw [line,red] (m-10-2) -| (m-9-3);
\foreach \f/\l[evaluate=\f as \t using int(\f+1)] in {3/a,5/b,7/c,9/d}{
\draw [line,red] (m-\f-1.east) --node[midway,above,text=black]{Yes, Pass (a,c)} ++ (2.5cm,0)coordinate[](\l);
\draw [line,red] (m-\f-1.east) -| ([xshift=1.5cm]m-\t-1.north);
}
\node[xshift=-2cm] at (m-3-1){Step 1(4)};
\node[xshift=-2cm] at (m-5-1){Step 2 (7)};
\node[xshift=-2cm] at (m-7-1){Step 3 (9)};
\node[xshift=-2cm] at (m-9-1){Step 4 (3)};
\node[xshift=-2cm,above] at (m-10-2){Step 5};
\draw [>=latex,-,red,thick] (a) --(d);
\draw [line,red] ($(a)!0.5!(d)$) -- (m-6-2);
\end{tikzpicture}
\end{adjustbox}
\caption{This is my flow chart}
\end{figure}
\end{document}