将标题添加到背景图层TikZ

Kostas 01/17/2017. 2 answers, 147 views
tikz-pgf tikz-styles backgrounds workflow

我想在块中添加一个标题,将标题放在块的顶部。

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{backgrounds, fit, positioning}

\begin{document}

\tikzstyle{block} = [draw, rectangle, 
                 text width=3cm, 
                 minimum height=1.7cm,
                 minimum width=3cm, 
                 fill=blue!20]

\begin{tikzpicture}[every text node part/.style={align=center}]

\node [block] (SparseRec) {Sparse \\ Reconstruction};
\node [block, below=1cm of SparseRec] (DenseRec) {Dense \\  Reconstruction};
\node [block, below=1cm of DenseRec] (MultiText) {Multi-texturing};     

\begin{scope}[on background layer]
\node [draw, double=black, dashed, distance = 3pt, fit=(SparseRec) (MultiText), fill=red, rounded corners, inner sep=.5cm] {r};
\end{scope}        

% Once the nodes are placed, connecting them is easy. 
\draw [->, line width=0.7mm] (SparseRec) -- (DenseRec);
\draw [->, line width=0.7mm] (DenseRec) -- (MultiText);

\end{tikzpicture}

\end{document} 

2 Answers


Zarko 06/28/2017.

您可以将标题写为红色块的标签:

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{arrows, backgrounds, fit, positioning}

\begin{document}
    \begin{tikzpicture}[%every text node part/.style={align=center}
node distance = 5mm,
 block/.style = {draw, rectangle,
                 text width=3cm,
                 minimum height=1.7cm, minimum width=3cm,
                 fill=blue!20,
                 align=center},
                    ]
\node [block] (SparseRec) {Sparse \\ Reconstruction};
\node [block, below=1cm of SparseRec] (DenseRec) {Dense \\  Reconstruction};
\node [block, below=1cm of DenseRec] (MultiText) {Multi-texturing};

\scoped[on background layer]
\node [draw, ultra thick, dashed, rounded corners, fill=red, 
       inner sep=.5cm,
       label=r,
       fit=(SparseRec) (MultiText)] {r};

% Once the nodes are placed, connecting them is easy.
\draw [->, line width=0.7mm] (SparseRec) -- (DenseRec);
\draw [->, line width=0.7mm] (DenseRec) -- (MultiText);
    \end{tikzpicture}
\end{document} 

在此处输入图像描述

Addendum:使用TikZ库chains ,上面的代码可以变得更简洁:

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{arrows.meta, backgrounds, 
                chains, % added
                fit, positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 10mm,
  start chain = going below,
 block/.style = {rectangle, draw, 
                 text width=3cm, align=center,
                 minimum height=1.7cm, minimum width=3cm,
                 fill=blue!20,
                 on chain, join=by {-Triangle, line width=0.7mm}% added
                 },
                    ]
\node [block] (SparseRec) {Sparse \\ Reconstruction};
\node [block] (DenseRec)  {Dense \\  Reconstruction}; % changed (simplified)
\node [block] (MultiText) {Multi-texturing};          % changed (simplified)  

\scoped[on background layer]
\node [draw, ultra thick, dashed, rounded corners, fill=red,
       inner sep=5mm,
       label={[font=\Large\bfseries]r},
       fit=(SparseRec) (MultiText)] {};
% connecting lines are drawn by macro "join"
    \end{tikzpicture}
\end{document} 

结果图像与第一个MWE几乎相同。


ferahfeza 01/17/2017.

使用\path

\begin{scope}[on background layer]
\node [draw, double=black, dashed, distance = 3pt, fit=(SparseRec) (MultiText), fill=red, rounded corners, inner sep=.5cm] {r};
\path (0,2) node[text=black] {r};
\end{scope} 

或者使用\node

\begin{scope}[on background layer]
\node [draw, double=black, dashed, distance = 3pt, fit=(SparseRec) (MultiText), fill=red, rounded corners, inner sep=.5cm] {r};
\node[text=black] at (0,2) {r};
\end{scope} 

HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
2 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
3 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
4 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
5 Eminem

Venom flac

Eminem. 2018. Writer: Eminem.
6 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
7 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
8 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
9 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
10 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
11 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
12 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
13 Lukas Graham

Love Someone flac

Lukas Graham. 2018. Writer: Don Stefano;Morten "Rissi" Ristorp;Morten "Pilo" Pilegaard;Jaramye Daniels;James Alan;David LaBrel;Lukas Forchhammer Graham.
14 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.
15 Deep Chills

Run Free flac

Deep Chills. 2018.
16 Khalid

Better flac

Khalid. 2018. Writer: Charlie Handsome;Jamil Chammas;Denis Kosiak;Tor Erik Hermansen;Mikkel Stoleer Eriksen;Khalid.
17 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.
18 NCT 127

Regular (English Version) flac

NCT 127. 2018.
19 Camila Cabello

Consequences (Orchestra) flac

Camila Cabello. 2018. Writer: Emily Lynn Weisband;Nicolle Galyon;Amy Wadge;Bart Schoudel;Frank Dukes;Camila Cabello.
20 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.

Related questions

Hot questions

Language

Popular Tags