如下面的工作示例所示,我在所有框周围都加了红框。我想给框贴上标签,但我做不到。我尝试使用 tikz 示例中给出的一些方法,但也没有成功。有人能帮我吗?提前致谢。
\documentclass[a4paper,11pt,twoside]{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath, graphicx, tikz, enumerate, amssymb, pgf}
\usepackage{fancyhdr}
\usepackage{cite}
\usepackage{setspace}
\usepackage{pgfplots}
\usepackage{slashbox}
\usepackage{bchart}
\usepackage{float}
\restylefloat{table}
\usepackage{caption}
\raggedbottom
\usepackage[bottom]{footmisc}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,shapes.symbols,automata}
\tikzset{
>=stealth',
punktchain/.style={
rectangle,
rounded corners,
% fill=black!10,
draw=black, very thick,
text width=10em,
minimum height=3em,
text centered,
on chain},
line/.style={draw, thick, <-},
element/.style={
tape,
top color=white,
bottom color=blue!50!black!60!,
minimum width=8em,
draw=blue!40!black!90, very thick,
text width=10em,
minimum height=3.5em,
text centered,
on chain},
every join/.style={->, thick,shorten >=1pt},
decoration={brace},
tuborg/.style={decorate},
tubnode/.style={midway, right=2pt},
every rectangle node/.style={color=black,thick}
}
\begin{document}
\begin{tikzpicture}
[node distance=.5cm,
start chain=going below,]
\node[punktchain, join] (timing) {Timing Solver};
\node[punktchain, join] (solver) {Solver};
\node[punktchain, join] (impl) {SolverImpl};
\node[punktchain, join] (stp) {STPSolver};
\node[punktchain, join, ] (stpimpl) {STPSolverImpl};
\draw[tuborg, decoration={brace}] let \p1=(solver.north), \p2=(impl.south) in
($(2.5, \y1)$) -- ($(2.5, \y2)$) node[tubnode] {*};
\draw[red,thick,dashed] ($(timing.north west)+(-1,0.3)$) rectangle ($(stpimpl.south east)+(1,-0.2)$);
\end{tikzpicture}
\end{document}
答案1
如果我正确理解了您的问题,您可以使用current bounding box
放置包含标签的节点:
\documentclass[a4paper,11pt,twoside]{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath, graphicx, tikz, enumerate, amssymb, pgf}
\usepackage{fancyhdr}
\usepackage{cite}
\usepackage{setspace}
\usepackage{pgfplots}
\usepackage{slashbox}
\usepackage{bchart}
\usepackage{float}
\restylefloat{table}
\usepackage{caption}
\raggedbottom
\usepackage[bottom]{footmisc}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,shapes.symbols,automata}
\tikzset{
>=stealth',
punktchain/.style={
rectangle,
rounded corners,
% fill=black!10,
draw=black, very thick,
text width=10em,
minimum height=3em,
text centered,
on chain},
line/.style={draw, thick, <-},
element/.style={
tape,
top color=white,
bottom color=blue!50!black!60!,
minimum width=8em,
draw=blue!40!black!90, very thick,
text width=10em,
minimum height=3.5em,
text centered,
on chain},
every join/.style={->, thick,shorten >=1pt},
decoration={brace},
tuborg/.style={decorate},
tubnode/.style={midway, right=2pt},
every rectangle node/.style={color=black,thick}
}
\begin{document}
\begin{tikzpicture}
[node distance=.5cm,
start chain=going below,]
\node[punktchain, join] (timing) {Timing Solver};
\node[punktchain, join] (solver) {Solver};
\node[punktchain, join] (impl) {SolverImpl};
\node[punktchain, join] (stp) {STPSolver};
\node[punktchain, join, ] (stpimpl) {STPSolverImpl};
\draw[tuborg, decoration={brace}] let \p1=(solver.north), \p2=(impl.south) in
($(2.5, \y1)$) -- ($(2.5, \y2)$) node[tubnode] {*};
\draw[red,thick,dashed] ($(timing.north west)+(-1,0.3)$) rectangle ($(stpimpl.south east)+(1,-0.2)$);
\node[anchor=south] at (current bounding box.north) {Some Text};
\end{tikzpicture}
\end{document}