![如何将 2 级概念思维导图节点放在矩形旁边](https://linux22.com/image/307354/%E5%A6%82%E4%BD%95%E5%B0%86%202%20%E7%BA%A7%E6%A6%82%E5%BF%B5%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE%E8%8A%82%E7%82%B9%E6%94%BE%E5%9C%A8%E7%9F%A9%E5%BD%A2%E6%97%81%E8%BE%B9.png)
我做了什么:
我已看过
pgf
手册。我已经在此网站上搜索过
mindmap
但没有找到解决方案。
我有一个mindmap
2 级有许多节点,1 级有八个节点。我认为最好让 2 级节点沿着(大)矩形的边排列,而 1 级节点仍将沿着以根节点为中心的圆排列;这将保证从 1 级节点到 2 级节点的路径不会交叉。我该如何实现这样的设计?
到目前为止我已经实现了这个目标:
这是一张手动干预最少的思维导图(改变了父节点V
和的起始角度VIII
)。出于显而易见的原因,我不得不将子节点从父节点II
和中删除IV
。如果我可以沿着矩形排列 2 级节点,就不需要留下任何东西了。
这是上面图片的来源。最终,这必须放在上面a4paper
,并附上一些文本。这些内容实际上是根据文档的实际标题自动生成的,但为了方便起见,我在这里提取了。
\documentclass[11pt,a4paper]{article}
\usepackage[margin=.2cm]{geometry}
\usepackage{xspace}
\usepackage[dvipsnames]{xcolor}
\usepackage{hyperref}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa [1] {{\ttfamily\hyphenchar\font45 \char`\\ #1}}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\begin{document}
\noindent
\resizebox{.9\paperwidth}{!}
{\begin{tikzpicture}[grow cyclic,
text width=2cm,
align=flush center,
every node/.style=concept,
concept color=orange!60,
level 1/.style={level distance=6cm,sibling angle=45},
level 2/.style={level distance=8cm,sibling angle=25}
]
\node {\textbf {The \etoc documentation}} child [concept color = teal!60]{node {I. Overview} child [concept color = teal!30]{node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}} child [concept color = teal!30]{node {4 Line styles and toc display style}} child [concept color = teal!30]{node {5 A first example}} child [concept color = teal!30]{node {6 A second example}} child [concept color = teal!30]{node {7 Linked list of the main package commands}}} child [concept color = yellow!80]{node {II. Arbitrarily many TOCs, and local ones too}} child [concept color = green!50]{node {III. Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace } child [concept color = green!30]{node {15 The TOC of TOCs}} child [concept color = green!30]{node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}} child [concept color = green!30]{node {17 A TOC with a fancy layout}} child [concept color = green!30]{node {18 Another compatibility mode}} child [concept color = green!30]{node {19 The TOC as a tree}} child [concept color = green!30]{node {20 The TOC as a molecule}} child [concept color = green!30]{node {21 The TOC as a TikZ Mindmap}} child [concept color = green!30]{node {22 The TOC as a table}}} child [concept color = teal!60]{node {IV. Commands for the toc line styles}} child [concept color = yellow!80]{node {V. Commands for the toc display style} [counterclockwise from =-40] child [concept color = yellow!40]{node {27 Specifying the toc display style}} child [concept color = yellow!40]{node {28 Starred variants of the \csa {tableofcontents} etc... commands}} child [concept color = yellow!40]{node {29 Table of contents for this part}}} child [concept color = green!50]{node {VI. Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace } child [concept color = green!30]{node {30 Summary of the main style commands}} child [concept color = green!30]{node {31 The package default line styles: \csa {etocdefaultlines}}} child [concept color = green!30]{node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }} child [concept color = green!30]{node {33 One more example of colored TOC layout}}} child [concept color = teal!60]{node {VII. Tips} child [concept color = teal!30]{node {34 ... and tricks}}} child [concept color = yellow!80]{node {VIII. The code}[counterclockwise from =-50] child [concept color = yellow!40]{node {35 Timestamp}} child [concept color = yellow!40]{node {36 Change history}} child [concept color = yellow!40]{node {37 Implementation}}} ;
\end{tikzpicture}}
\end{document}
以下是父母和孩子的数据,以更清晰的显示方式显示,带有换行符和空格,方便那些想要复制/粘贴进行测试的温和人士:
\node {\textbf {The \etoc documentation}}
child [concept color = teal!60]
{node {I. Overview}
child [concept color = teal!30]{node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}}
child [concept color = teal!30]{node {4 Line styles and toc display style}}
child [concept color = teal!30]{node {5 A first example}}
child [concept color = teal!30]{node {6 A second example}}
child [concept color = teal!30]{node {7 Linked list of the main package commands}}
}
child [concept color = yellow!80]{node {II. Arbitrarily many TOCs, and local ones too}}
child [concept color = green!50]
{node {III. Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace }
child [concept color = green!30]{node {15 The TOC of TOCs}}
child [concept color = green!30]{node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}}
child [concept color = green!30]{node {17 A TOC with a fancy layout}}
child [concept color = green!30]{node {18 Another compatibility mode}}
child [concept color = green!30]{node {19 The TOC as a tree}}
child [concept color = green!30]{node {20 The TOC as a molecule}}
child [concept color = green!30]{node {21 The TOC as a TikZ Mindmap}}
child [concept color = green!30]{node {22 The TOC as a table}}
}
child [concept color = teal!60]
{node {IV. Commands for the toc line styles}}
child [concept color = yellow!80]
{node {V. Commands for the toc display style} [counterclockwise from =-40]
child [concept color = yellow!40]{node {27 Specifying the toc display style}}
child [concept color = yellow!40]{node {28 Starred variants of the \csa {tableofcontents} etc... commands}}
child [concept color = yellow!40]{node {29 Table of contents for this part}}
}
child [concept color = green!50]
{node {VI. Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }
child [concept color = green!30]{node {30 Summary of the main style commands}}
child [concept color = green!30]{node {31 The package default line styles: \csa {etocdefaultlines}}}
child [concept color = green!30]{node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }}
child [concept color = green!30]{node {33 One more example of colored TOC layout}}
}
child [concept color = teal!60]
{node {VII. Tips}
child [concept color = teal!30]{node {34 ... and tricks}}
}
child [concept color = yellow!80]
{node {VIII. The code}[counterclockwise from =-50]
child [concept color = yellow!40]{node {35 Timestamp}}
child [concept color = yellow!40]{node {36 Change history}}
child [concept color = yellow!40]{node {37 Implementation}}
} ;
谢谢下面这个答案我得到了一些用于播放宽度的起始代码。我还没有尝试过矩形,我知道需要做什么,但目前对我来说太复杂了,不仅因为它非常数学化,还因为它需要知道用 TikZ 进行计算的方式比我目前知道的更好(目前还不知道)。但我从中学到了很多回答如何将孙子孙女放在一个圆圈上。因此我可以添加缺失的部分,这是我现在得到的结果:
这将形成一个完美的标题页。
\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}
\newcount\tikznumberofcurrentgrandchild
\def\tikzmycustomgrowth {%
\pgftransformreset
\ifnum\tikztreelevel=1
\pgftransformrotate {(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1)}%
\fi
\ifnum\tikztreelevel=2
\pgftransformrotate {(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentgrandchild-4)}%
\global\advance\tikznumberofcurrentgrandchild by 1
\fi
\pgftransformxshift {\the\tikzleveldistance}%
}
\tikzset{
branch color/.style={
concept color=#1!white,
every child/.append style={concept color=#1!white!30!white},
}
}
\begin{document}
\begin{tikzpicture}[mindmap,
growth function=\tikzmycustomgrowth,
nodes={concept},
concept color=orange!60,
root concept/.append style={font=\huge, minimum size=5.5cm},
level 1/.append style={level distance=6.5cm, sibling angle=360/8},
level 1 concept/.append style={font=\Large,minimum size=4cm},
level 2/.append style={level distance=12.5cm, sibling angle=360/35},
% distance par rapport au CENTRE ! (avec le code tel qu'en ce moment)
]
\tikznumberofcurrentgrandchild=0
\node [root concept]{The \etoc package}
child [branch color=teal!60]{node {I Overview}
child {node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}}
child {node {4 Line styles and toc display style}}
child {node {5 A first example}}
child {node {6 A second example}}
child {node {7 Linked list of the main package commands}}}
child [branch color=yellow!80]{node {II Arbitrarily many TOCs, and local ones too}
child {node {8 Labeling and reusing elsewhere}}
child {node {9 A powerful functionality of {\color {joli}\ttfamily \bfseries etoc}\xspace : the re-assignment of levels with \csa {etocsetlevel}}}
child {node {10 The \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}depth} and \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}next\discretionary {-}{}{}toc\discretionary {-}{}{}depth} commands}}
child {node {11 The command \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}dep\discretionary {-}{}{}th.toc}}}
child {node {12 The commands \csa {etoc\discretionary {-}{}{}depth\discretionary {-}{}{}tag.toc} and \csa {etocsettagdepth}}}
child {node {13 Adding commands to the \texttt {.toc} file}}
child {node {14 Two Examples}}}
child [branch color=green!50]{node {III Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace }
child {node {15 The TOC of TOCs}}
child {node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}}
child {node {17 A TOC with a fancy layout}}
child {node {18 Another compatibility mode}}
child {node {19 The TOC as a tree}}
child {node {20 The TOC as a molecule}}
child {node {21 The TOC as a TikZ Mindmap}}
child {node {22 The TOC as a table}}}
child [branch color=teal!60]{node {IV Commands for the toc line styles}
child {node {23 The \csa {etocsetstyle} command}}
child {node {24 The \csa {etocsetlevel} command}}
child {node {25 Scope of commands added to the \texttt {.toc} file}}
child {node {26 Am I also red?}}}
child [branch color=yellow!80]{node {V Commands for the toc display style}
child {node {27 Specifying the toc display style}}
child {node {28 Starred variants of the \csa {tableofcontents} etc... commands}}
child {node {29 Table of contents for this part}}}
child [branch color=green!50]{node {VI Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }
child {node {30 Summary of the main style commands}}
child {node {31 The package default line styles: \csa {etocdefaultlines}}}
child {node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }}
child {node {33 One more example of colored TOC layout}}}
child [branch color=teal!60]{node {VII Tips}
child {node {34 ... and tricks}}}
child [branch color=yellow!80]{node {VIII The code}
child {node {35 Timestamp}}
child {node {36 Change history}}
child {node {37 Implementation}}} ;
\end{tikzpicture}
\end{document}
答案1
编辑
答案是(再次)是的,只要您带了足够的钱\if
。
\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}
\newcount\tikznumberofcurrentgrandchild
\def\tikzretangulargroth{%
\pgftransformreset
\ifnum\tikztreelevel=1
\pgftransformrotate{55+((\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild)}%
\pgftransformxshift{\the\tikzleveldistance}%
\fi
\ifnum\tikztreelevel=2
\pgfmathsetmacro\tikzoffsetofcurrentchild{(\tikzsiblingdistance)*(\tikznumberofcurrentgrandchild)}%
\ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth pt
\pgftransformxshift{\tikzlevelwidth/2-\tikzoffsetofcurrentchild}
\pgftransformyshift{\tikzlevelheight/2}
\else
\pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
\ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight pt
\pgftransformxshift{-\tikzlevelwidth/2}
\pgftransformyshift{\tikzlevelheight/2-\tikzoffsetofcurrentchild}
\else
\pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelheight}%
\ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth pt
\pgftransformxshift{-\tikzlevelwidth/2+\tikzoffsetofcurrentchild}
\pgftransformyshift{-\tikzlevelheight/2}
\else
\pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
\ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight pt
\pgftransformxshift{\tikzlevelwidth/2}
\pgftransformyshift{-\tikzlevelheight/2+\tikzoffsetofcurrentchild}
\fi\fi\fi\fi
\global\advance\tikznumberofcurrentgrandchild by1
\fi
}
\tikzset{
branch color/.style={
concept color=#1!white,
every child/.append style={concept color=#1!white!30!white},
},
level width/.store in=\tikzlevelwidth,
level height/.store in=\tikzlevelheight
}
\begin{document}
\tikznumberofcurrentgrandchild=0
\begin{tikzpicture}[
mindmap,
growth function=\tikzretangulargroth,
nodes={concept},
concept color=orange!60,
root concept/.append style={font=\huge, minimum size=5.5cm},
level 1/.append style={level distance=6.5cm, sibling angle=360/8},
level 1 concept/.append style={font=\Large,minimum size=4cm},
level 2/.append style={level width=20cm,level height=28.7cm, sibling distance=2.77cm},
% A4 paper with margin=.5cm
]
\node [root concept]{The \etoc package}
child [branch color=teal!60]{node {I Overview}
child {node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}}
child {node {4 Line styles and toc display style}}
child {node {5 A first example}}
child {node {6 A second example}}
child {node {7 Linked list of the main package commands}}
}
child [branch color=yellow!80]{node {II Arbitrarily many TOCs, and local ones too}
child {node {8 Labeling and reusing elsewhere}}
child {node {9 A powerful functionality of {\color {joli}\ttfamily \bfseries etoc}\xspace : the re-assignment of levels with \csa {etocsetlevel}}}
child {node {10 The \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}depth} and \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}next\discretionary {-}{}{}toc\discretionary {-}{}{}depth} commands}}
child {node {11 The command \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}dep\discretionary {-}{}{}th.toc}}}
child {node {12 The commands \csa {etoc\discretionary {-}{}{}depth\discretionary {-}{}{}tag.toc} and \csa {etocsettagdepth}}}
child {node {13 Adding commands to the \texttt {.toc} file}}
child {node {14 Two Examples}}
}
child [branch color=green!50]{node {III Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace }
child {node {15 The TOC of TOCs}}
child {node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}}
child {node {17 A TOC with a fancy layout}}
child {node {18 Another compatibility mode}}
child {node {19 The TOC as a tree}}
child {node {20 The TOC as a molecule}}
child {node {21 The TOC as a TikZ Mindmap}}
child {node {22 The TOC as a table}}
}
child [branch color=teal!60]{node {IV Commands for the toc line styles}
child {node {23 The \csa {etocsetstyle} command}}
child {node {24 The \csa {etocsetlevel} command}}
child {node {25 Scope of commands added to the \texttt {.toc} file}}
child {node {26 Am I also red?}}
}
child [branch color=yellow!80]{node {V Commands for the toc display style}
child {node {27 Specifying the toc display style}}
child {node {28 Starred variants of the \csa {tableofcontents} etc... commands}}
child {node {29 Table of contents for this part}}
}
child [branch color=green!50]{node {VI Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }
child {node {30 Summary of the main style commands}}
child {node {31 The package default line styles: \csa {etocdefaultlines}}}
child {node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }}
child {node {33 One more example of colored TOC layout}}
}
child [branch color=teal!60]{node {VII Tips}
child {node {34 ... and tricks}}
}
child [branch color=yellow!80]{node {VIII The code}
child {node {35 Timestamp}}
child {node {36 Change history}}
child {node {37 Implementation}}
}
;
\end{tikzpicture}
\end{document}
旧答案
答案是是的只要您自己编写即可growth function
。下面的示例虽然不是矩形,但说明了一些想法。
\tikz@grow@concentric
由以下项定义并挂钩
growth function=\tikz@grow@concentric
- 使用
\pgftransformreset
和一些支持变量,节点可以位于我们想要的任何地方。在这种情况下,2 级概念沿圆圈排列。这表明它们的位置在某种程度上不(仅)取决于其父级的位置。 - 我定义
branch color
,这样我们只需一步就可以分配 1 级和 2 级概念颜色。
缺点是
钛钾Z 不会为您计算子代/后代。它首先排版父代。因此
sibling angle=360/23
是手动分配的。您还需要给出每个分支的正确子女人数
noc=5
。(NOC 代表子女人数)\tikz@grow@concentric
是为 2 级思维导图设计的。更多级别需要更多变量和更多 if 语句。- 黄色部分看起来很奇怪。我不知道为什么。
代码
\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap,decorations}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}
\makeatletter
\newcount\tikzcountgrandchild
\def\tikz@grow@concentric{%
\pgftransformreset%
\pgftransformrotate{(\pgfkeysvalueof{/tikz/sibling angle})*(\tikzcountgrandchild)}%
\ifnum\tikztreelevel=1
\pgftransformrotate{(\pgfkeysvalueof{/tikz/sibling angle})*(\pgfkeysvalueof{/tikz/noc}-1)/2}%
\fi
\pgftransformxshift{\the\tikzleveldistance}%
\ifnum\tikztreelevel=2
\global\advance\tikzcountgrandchild by1
\fi
}
\tikzset{
noc/.initial=0,
branch color/.style={
concept color=#1!white,
every child/.append style={concept color=#1!white!30!white},
}
}
\begin{document}
\begin{tikzpicture}[text width=2cm,align=flush center,
mindmap,growth function=\tikz@grow@concentric,
sibling angle=360/23,nodes={concept},concept color=orange!60,
level 1/.style={level distance=10cm},
level 2/.style={level distance=16cm}
]
\node{\textbf{The \etoc documentation}}
child[noc=5,branch color=teal!60]{node{I. Overview}
child{node{3 Do I need to be a geek to use{\color{joli}\ttfamily \bfseries etoc}\xspace ?}}
child{node{4 Line styles and toc display style}}
child{node{5 A first example}}
child{node{6 A second example}}
child{node{7 Linked list of the main package commands}}
}
child[noc=0,branch color=yellow!80]{node{II. Arbitrarily many TOCs, and local ones too}
}
child[noc=7,branch color=green!50]{node{III. Surprising uses of{\color{joli}\ttfamily \bfseries etoc}\xspace }
child{node{15 The TOC of TOCs}}
child{node{16 Arbitrary ``Lists Of...'', \csa{etoctoccontentsline}}}
child{node{17 A TOC with a fancy layout}}
child{node{18 Another compatibility mode}}
child{node{19 The TOC as a tree}}
child{node{21 The TOC as a TikZ Mindmap}}
child{node{22 The TOC as a table}}
}
child[noc=0,branch color=teal!60]{node{IV. Commands for the toc line styles}
}
child[noc=3,branch color=yellow!80]{node{V. Commands for the toc display style}
child{node{27 Specifying the toc display style}}
child{node{28 Starred variants of the \csa{tableofcontents} etc... commands}}
child{node{29 Table of contents for this part}}
}
child[noc=4,branch color=green!50]{node{VI. Using and customizing{\color{joli}\ttfamily \bfseries etoc}\xspace }
child{node{30 Summary of the main style commands}}
child{node{31 The package default line styles: \csa{etocdefaultlines}}}
child{node{32 Customizing{\color{joli}\ttfamily \bfseries etoc}\xspace }}
child{node{33 One more example of colored TOC layout}}
}
child[noc=1,branch color=teal!60]{node{VII. Tips}
child{node{34 ... and tricks}}}
child[noc=3,branch color=yellow!80]{node{VIII. The code}
child{node{35 Timestamp}}
child{node{36 Change history}}
child{node{37 Implementation}}
}
;
\end{tikzpicture}
\end{document}