Tikz:在思维导图中很好地填充概念

Tikz:在思维导图中很好地填充概念

使用此代码时:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{trees,mindmap}

\tikzset{grow cyclic list/.code={%
  \def\tikzgrowthpositions{{#1}}%
  \foreach \n [count=\i,remember=\i]in {#1}{}%
  \let\tikzgrowthpositionscount=\i%
  \tikzset{growth function=\tikzgrowcycliclist}}}
\def\tikzgrowcycliclist{%
  \pgftransformshift{%
    \pgfpointpolar{\tikzgrowthpositions[mod(\the\tikznumberofcurrentchild-1,\tikzgrowthpositionscount)]}%
      {\the\tikzleveldistance}}}

\tikzset{every node/.style={font={\fontsize{12pt}{14pt}\selectfont}}}

\begin{document}

\begin{tikzpicture}[mindmap, concept color=blue!20, every child node/.style={concept}]

\path node[concept] {Mathematical Modeling and Machine Learning} [grow cyclic list={90,50,0}]
    child { node {clustering} [grow cyclic list={110,55}]
        child { node {K-means} }
        child { node {hie\-rar\-chi\-cal clustering} }
    }
    child { node {dimension reduction} [clockwise from=50]
        child { node {PCA} }
    }
    child[level distance=10cm] { node {regression} [grow cyclic list={135,90,45,0}]
        child { node {training} [grow cyclic list={180,135,90}]
            child { node {least squares} }
            child { node {linear least squares} }
            child { node {regression to the mean} }
        }
        child[level distance=5cm] { node {diagnostics} [grow cyclic list={135,90,45}]
            child[level distance=4cm] { node {re\-si\-duals, residual variance} }
            child { node {variance inflation} }
            child[level distance=4cm] { node {va\-rian\-ces and quasi likelihood} }
        }
        child[level distance=10cm] { node {model search, comparison and selection} }
        child[level distance=10cm] { node {multivariable regression}
            child { node {multivariable simulation} }
            child { node {dummy variables} }
            child { node {interactions} }
            child { node {interpreting coefficients} }
        }
    }
;

\end{tikzpicture}
\end{document}

我评论了这一行\tikzset{every node/.style={font={\fontsize{12pt}{14pt}\selectfont}}}

我得到了很好的想法

在此处输入图片描述

但如果我使用 12pt 字体,我会得到

在此处输入图片描述

查看带有文本“方差和准似然”的气泡。我该怎么做才能使文本在概念中格式化,但使用 12pt 字体?

答案1

如果文档字体不是 12pt(通常在图表中使用时是这种情况),则可以为该特定图表设置它。但您应该为整个图表设置它,以便正确配置地图。

例如:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{mindmap}

\tikzset{grow cyclic list/.code={%
  \def\tikzgrowthpositions{{#1}}%
  \foreach \n [count=\i,remember=\i]in {#1}{}%
  \let\tikzgrowthpositionscount=\i%
  \tikzset{growth function=\tikzgrowcycliclist}}}
\def\tikzgrowcycliclist{%
  \pgftransformshift{%
    \pgfpointpolar{\tikzgrowthpositions[mod(\the\tikznumberofcurrentchild-1,\tikzgrowthpositionscount)]}%
      {\the\tikzleveldistance}}}

\begin{document}
{\fontsize{12pt}{14pt}\selectfont
\begin{tikzpicture}[mindmap, concept color=blue!20, every child node/.style={concept}]

\path node[concept] {Mathematical Modeling and Machine Learning} [grow cyclic list={90,50,0}]
    child { node {clustering} [grow cyclic list={110,55}]
        child { node {K-means} }
        child { node {hie\-rar\-chi\-cal clustering} }
    }
    child { node {dimension reduction} [clockwise from=50]
        child { node {PCA} }
    }
    child[level distance=10cm] { node {regression} [grow cyclic list={135,90,45,0}]
        child { node {training} [grow cyclic list={180,135,90}]
            child { node {least squares} }
            child { node {linear least squares} }
            child { node {regression to the mean} }
        }
        child[level distance=5cm] { node {diagnostics} [grow cyclic list={135,90,45}]
            child[level distance=4cm] { node {re\-si\-duals, residual variance} }
            child { node {variance inflation} }
            child[level distance=4cm] { node {va\-rian\-ces and quasi likelihood} }
        }
        child[level distance=10cm] { node {model search, comparison and selection} }
        child[level distance=10cm] { node {multivariable regression}
            child { node {multivariable simulation} }
            child { node {dummy variables} }
            child { node {interactions} }
            child { node {interpreting coefficients} }
        }
    }
;

\end{tikzpicture}}
\end{document}

12pt 地图

请注意,地图的设置默认配置为对距离根节点较多的节点使用较小的字体。如果您不想这样,则需要覆盖需要更改的任何级别的节点的默认样式。仅仅更改字体大小是不够的,因为还需要调整节点大小等才能获得合理的结果。

以下是各个级别的样式的相关默认设置。(该库显然尚未更新以使用当前语法,并且仍然使用已弃用的\tikzstyle。)

% default settings copied from tikzlibrarymindmap.code.tex 

\tikzstyle{root concept}=   [minimum size=4cm,text width=3.5cm,font=\pgfutil@font@large]
\tikzstyle{level 1 concept}=[minimum size=2.25cm,
                             level distance=5cm,
                             text width=2cm,
                             sibling angle=60,
                             font=\pgfutil@font@small]
\tikzstyle{level 2 concept}=[minimum size=1.75cm,%
                             level distance=2.9cm,%
                             text width=1.5cm,%
                             sibling angle=60,%
                             font=\pgfutil@font@footnotesize]
\tikzstyle{level 3 concept}=[minimum size=1.15cm,%
                             text width=1cm,%
                             level distance=2.4cm,%
                             sibling angle=30,%
                             font=\pgfutil@font@tiny]
\tikzstyle{level 4 concept}=[minimum size=0.9cm,%
                             text width=0.7cm,
                             level distance=1.85cm,%
                             sibling angle=30,%
                             font=\pgfutil@font@tiny]

因此,如果您在第 3 级节点中排版 12pt 文本,会发生什么情况?如果您在宽度为 1cm 的任何框中排版 12pt 文本,会发生什么情况?它根本无法很好地适应!

因此,需要进行更广泛的更改才能产生合理的结果。例如:

\documentclass[tikz,border=5,12pt]{standalone}
\usetikzlibrary{mindmap}

\tikzset{grow cyclic list/.code={%
  \def\tikzgrowthpositions{{#1}}%
  \foreach \n [count=\i,remember=\i]in {#1}{}%
  \let\tikzgrowthpositionscount=\i%
  \tikzset{growth function=\tikzgrowcycliclist}}}
\def\tikzgrowcycliclist{%
  \pgftransformshift{%
    \pgfpointpolar{\tikzgrowthpositions[mod(\the\tikznumberofcurrentchild-1,\tikzgrowthpositionscount)]}%
      {\the\tikzleveldistance}}}
\begin{document}
  \begin{tikzpicture}[
    mindmap,
    every node/.append style={execute at begin node=\hskip0pt},
    level 1 concept/.append style={font=\normalsize},
    level 2 concept/.append style={
      font=\normalsize,
      minimum size=2.25cm,
      text width=2cm,
      sibling angle=60,
      level distance=3.5cm,
    },
    level 3 concept/.append style={
      font=\normalsize,
      minimum size=2cm,
      text width=1.75cm,
      sibling angle=60,
      level distance=3.25cm
    },
    concept color=blue!20,
    every child node/.style={concept}
  ]

\path node[concept] {Mathematical Modeling and Machine Learning} [grow cyclic list={110,70,0}]
    child { node {clustering} [grow cyclic list={110,55}]
        child { node {K-means} }
        child { node {hierarchical clustering} }
    }
    child { node {dimension reduction} [clockwise from=50]
        child { node {PCA} }
    }
    child[level distance=10cm] { node {regression} [grow cyclic list={135,75,40,0}]
        child { node {training} [grow cyclic list={180,135,90}]
            child { node {least squares} }
            child { node {linear least squares} }
            child { node {regression to the mean} }
        }
        child[level distance=5cm] { node {diagnostics} [grow cyclic list={125,90,45}]
            child[level distance=4cm] { node {residuals, residual variance} }
            child { node {variance inflation} }
            child[level distance=4cm] { node {variances and quasi likelihood} }
        }
        child[level distance=10cm] { node {model search, comparison and selection} }
        child[level distance=10cm] { node {multivariable regression}
            child { node {multivariable simulation} }
            child { node {dummy variables} }
            child { node {interactions} }
            child { node {interpreting coefficients} }
        }
    }
;
\end{tikzpicture}
\end{document}

生产

所有节点均为 12pt

相关内容