我怎样才能将节点(框)的形状改变为其他形状?

我怎样才能将节点(框)的形状改变为其他形状?

我想使用包绘制家谱genealogytree。我不知道如何将节点的形状从简单的盒子更改为更复杂的东西,例如徽章。盒子总是矩形。所以我的问题是如何将其更改为其他形状。感谢您的帮助和提示。

我尝试通过 来完成tcbset,但每次尝试都失败了。所以,我担心这不是正确的方法。

\documentclass{article}

\usepackage[czech]{babel}
\usepackage[cp1250]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}    
\usepackage[all]{genealogytree}    
\usepackage{incgraph} 
\usepackage{tikz,pgf}

\begin{document}
\begin{inctext}
\begin{tikzpicture}    
    \genealogytree[template=signpost]{
    parent{           
           c[female]{Silvie Polaková} 
           g[male]{Alex Homola}  
           parent{
                  g[male]{Radomir Palacek}         
                 } 
           parent{   
                  c[female]{Marie Homolova}
                  g[female]{Zdenka Homolova}                  
                  parent{
                         g[female]{Marie Drastichova}
                        }
                  parent{
                         c[female]{Marie Homolova}

                         g[male]{Augustin Homola}
                         c[male]{Josef Homola}

                         parent{
                                g[female]{Amalie Tomanková}
                               }                              
                        } 
                  }
           }         
     }            
\end{tikzpicture}
\end{inctext}
\end{document}

答案1

box选项用于向底层框处理器提供选项。这可以是tcolorbox或直接tikz

例如,

box={bean arc,sharp corners=north,bottom=5mm},

将盒子重塑为一些徽章状。

malefemale是可以重新定义以应用男性/女性特定设置的样式。如果tcolorbox用于处理,则可以使用以下方式设置这些样式tcbset您已经想到的方法来设置这些样式。

参见以下完整示例:

\documentclass{article}

\usepackage[czech]{babel}
\usepackage[cp1250]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[all]{genealogytree}
\usepackage{incgraph}
\usepackage{tikz,pgf}


\begin{document}
\begin{inctext}[border=3mm]
\begin{tikzpicture}
    \genealogytree[template=signpost,
      level size=2cm,
      box={bean arc,sharp corners=north,bottom=5mm},
      tcbset={
        male/.style={
          colframe=blue!50!black,
          interior style={top color=blue!20,bottom color=blue!50!yellow!5},
          drop fuzzy shadow=blue!25!black!30},
        female/.style={
          colframe=red!50!black,
          colback=red!50!yellow!5,
          interior style={top color=red!20,bottom color=red!50!yellow!5},
          drop fuzzy shadow=red!25!black!30}
      },
      ]{
    parent{
           c[female]{Silvie Polaková}
           g[male]{Alex Homola}
           parent{
                  g[male]{Radomir Palacek}
                 }
           parent{
                  c[female]{Marie Homolova}
                  g[female]{Zdenka Homolova}
                  parent{
                         g[female]{Marie Drastichova}
                        }
                  parent{
                         c[female]{Marie Homolova}

                         g[male]{Augustin Homola}
                         c[male]{Josef Homola}

                         parent{
                                g[female]{Amalie Tomanková}
                               }
                        }
                  }
           }
     }
\end{tikzpicture}
\end{inctext}
\end{document}

在此处输入图片描述

答案2

默认情况下,genealogytree使用\tcboxfit(来自tcolorbox)绘制树叶,但您可以使用processing选项更改它并选择其他工具。其中之一是tikznode。在这种情况下,您可以使用任何node可用的选项来配置树的元素。

以下代码使用heraldic shield定义在在 LaTeX 中绘制徽章。看起来需要进行一些调整,但我希望这可以作为一个起点。

\documentclass{article}

\usepackage[czech]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{lmodern}    
\usepackage[all]{genealogytree}    
\usepackage{incgraph} 

\makeatletter    

\pgfkeys{/tikz/.cd,
  corner radius/.initial=1.5075cm,
  height shield/.initial=2.25cm,
  minimum width=3cm,
  minimum height=1.5cm,
}

\pgfdeclareshape{heraldic shield}{% taken and modified from page 631 of the manual
  \inheritsavedanchors[from=rectangle] %  this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}

   \savedmacro\cornerradius{%
    \edef\cornerradius{\pgfkeysvalueof{/tikz/corner radius}}%
  }

   \savedmacro\heightshield{%
    \edef\heightshield{\pgfkeysvalueof{/tikz/height shield}}%
  }

  \savedmacro\posarc{%
    \edef\posarc{1.75cm*\heightshield}%
  }

  \backgroundpath{%  this is new
    %  store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    %  construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
     \pgfpatharc{360}{270}{\cornerradius}%
     \pgfpatharc{270}{180}{\cornerradius}%
     \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathclose
 }

  \savedanchor{\bottom}{
    \pgf@y=-\heightshield%
    \pgf@x=0cm %
    }

    \savedanchor{\arcleft}{
    \pgf@y=-\posarc%
    \pgf@x=0.9cm %
    }
    \savedanchor{\arcright}{
    \pgf@y=-\posarc%
    \pgf@x=-0.9cm %
    }
 \anchor{bottom}{\bottom}
 \anchor{arc left}{\arcleft}
 \anchor{arc right}{\arcright}
}
\makeatother

\tikzset{arms/.style={draw=#1, line width=1mm, heraldic shield, text width=20mm, align=center}}

\begin{document}
\begin{inctext}
\begin{tikzpicture}    
    \genealogytree[
    processing=tikznode,
    male/.style={box={arms=blue}},
    female/.style={box={arms=red}},
    box={arms=black}]{
    parent{           
           c[female]{Silvie Polaková} 
           g[male]{Alex Homola}  
           parent{
                  g[male]{Radomir Palacek}         
                 } 
           parent{   
                  c[female]{Marie Homolova}
                  g[female]{Zdenka Homolova}                  
                  parent{
                         g[female]{Marie Drastichova}
                        }
                  parent{
                         c[female]{Marie Homolova}

                         g[male]{Augustin Homola}
                         c[male]{Josef Homola}

                         parent{
                                g[female]{Amalie Tomanková}
                               }                              
                        } 
                  }
           }         
     }            
\end{tikzpicture}
\end{inctext}
\end{document}

在此处输入图片描述

相关内容