帮助修改 Sunburst Chart 代码以用于家谱目的

帮助修改 Sunburst Chart 代码以用于家谱目的

我采用了之前在此处发布的代码:有没有办法在 LaTeX 中制作“旭日图”(多层饼图)?

我想修改它以用于家谱目的。我有我想要的设置,但我不确定如何修改该函数以便我可以为每个 arctext 片段添加两行文本。

有人能帮助我理解这个函数,以便我可以修改它来显示两行吗?

我认为框的“高度”已经编码了,我可以使用该功能来相应地调整文本大小。

谢谢。

\documentclass[border=5pt]{standalone}
\usepackage{xcolor}
\definecolor{orange1}{HTML}{F1753A}
\definecolor{orange2}{HTML}{F7A13E}
\definecolor{orange3}{HTML}{FC6300} 
\definecolor{root}{HTML}{B2B2B2}
\usepackage{tikz}
\usepackage{pgfmath}
\usetikzlibrary{decorations.text, arrows.meta,calc,shadows.blur,shadings}
\renewcommand*\familydefault{\sfdefault} % Set font to serif family

% arctext from Andrew code with modifications:
%Variables: 1: ID, 2:Style 3:box height 4: Radious 5:start-angl 6:end-angl 7:text {format along path} 
\def\arctext[#1][#2][#3](#4)(#5)(#6)#7{

\draw[
color=white,
thick,
line width=1.3pt,
fill=#2
]
(#5:#4cm+#3) coordinate (above #1) arc (#5:#6:#4cm+#3)
-- (#6:#4) coordinate (right #1) -- (#6:#4cm-#3) coordinate (below right #1) 
arc (#6:#5:#4cm-#3) coordinate (below #1)
-- (#5:#4) coordinate (left #1) -- cycle;
\def\a#1{#4cm+#3}
\def\b#1{#4cm-#3}
\path[
decoration={
    raise = -0.5ex, % Controls relavite text height position.
    text  along path,
    text = {#7},
    text align = center,        
},
decorate
]
(#5:#4) arc (#5:#6:#4);
}

%arcarrow, this is mine, for beerware purpose...
%Function: Draw an arrow from arctex coordinate specific nodes to another 
%Arrow start at the start of arctext box and could be shifted to change the position
%to avoid go over another box.
%Var: 1:Start coordinate 2:End coordinate 3:angle to shift from acrtext box  
\def\arcarrow[#1](#2)(#3)[#4]{
\draw[thick,-,>=latex,color=#1,line width=1pt,shorten >=-2pt, shorten <=-2pt] 
    let \p1 = (#2), \p2 = (#3), % To access cartesian coordinates x, and y.
        \n1 = {veclen(\x1,\y1)}, % Distance from the origin
        \n2 = {veclen(\x2,\y2)}, % Distance from the origin
        \n3 = {atan2(\y1,\x1)} % Angle where acrtext starts.
    in (\n3-#4: \n1) -- (\n3-#4: \n2); % Draw the arrow.
}

\begin{document}
\begin{tikzpicture}[
    % Environment Cfg
    font=\sf    \scriptsize,
    % Styles
    myarrow/.style={
        thick,
        -latex,
    },
    Center/.style ={
        circle,
        fill=white,
        text=root,
        align=center,
        font =\footnotesize,
        inner sep=1pt,          
    },
]

% Drawing the center
\node[Center](ROOT) at (0,0) {Test \\ Boy};

% Drawing the Tex Arcs

% \Arctext[ID][box-style][box-height](radious)(start-angl)(end-angl){|text-styles| Text}
% Node 1:  Father 
\arctext[N1][orange1][15pt](1.5)(180)(0){|\footnotesize\bf\color{white}| John Boy  B. 12 Jun 2016};

%Sub 1: Grandfather
\arctext[N1S1][orange1][13pt](2.5)(180)(90){|\footnotesize\bf\color{white}| Sub1};

    %Sub 1-Sub 1: Great Grandfather
    \arctext[N1S1S1][orange1][8pt](3.25)(180)(135){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N1S1S1S1][orange1][8pt](3.8)(180)(157.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N1S1S1S2][orange1][8pt](3.8)(157.5)(135){|\footnotesize\bf\color{white}| Sub1-Sub2}        

    %Sub 1-Sub 2: Great Grandmother
    \arctext[N1S1S2][orange1][8pt](3.25)(135)(90){|\footnotesize\bf\color{white}| Sub1-Sub2}

        %Sub 1-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N1S1S2S1][orange1][8pt](3.8)(135)(112.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N1S1S2S2][orange1][8pt](3.8)(112.5)(90){|\footnotesize\bf\color{white}| Sub1-Sub2} 


%Sub 2: Grandmother
\arctext[N1S2][orange1][13pt](2.5)(90)(0){|\footnotesize\bf\color{white}| Sub2};

        %Sub 2-Sub 1: Great Grandfather
    \arctext[N1S2S1][orange1][8pt](3.25)(90)(45){|\footnotesize\bf\color{white}| Sub2-Sub1};

        %Sub 2-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N1S2S1S1][orange1][8pt](3.8)(90)(67.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 2-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N1S2S1S2][orange1][8pt](3.8)(67.5)(45){|\footnotesize\bf\color{white}| Sub1-Sub2}  

    %Sub 2-Sub 2: Great Grandmother
            \arctext[N1S2S2][orange1][8pt](3.25)(45)(0){|\footnotesize\bf\color{white}| Sub2-Sub2};

        %Sub 2-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N1S2S2S1][orange1][8pt](3.8)(45)(22.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 2-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N1S2S2S2][orange1][8pt](3.8)(22.5)(0){|\footnotesize\bf\color{white}| Sub1-Sub2}   

\arctext[N2][orange2][15pt](1.5)(180)(360){|\footnotesize\bf\color{white}| John Boy B. 12 Jun 2016};

%Sub 1: Grandfather
\arctext[N2S1][orange2][13pt](2.5)(180)(270){|\footnotesize\bf\color{white}| Sub1};

    %Sub 1-Sub 1: Great Grandfather
    \arctext[N2S1S1][orange2][8pt](3.25)(180)(225){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N2S1S1S1][orange2][8pt](3.8)(180)(202.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N2S1S1S2][orange2][8pt](3.8)(202.5)(225){|\footnotesize\bf\color{white}| Sub1-Sub2}        

    %Sub 1-Sub 2: Great Grandmother
    \arctext[N2S1S2][orange2][8pt](3.25)(225)(270){|\footnotesize\bf\color{white}| Sub1-Sub2}

        %Sub 1-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N2S1S2S1][orange2][8pt](3.8)(225)(247.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 1-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N2S1S2S2][orange2][8pt](3.8)(247.5)(270){|\footnotesize\bf\color{white}| Sub1-Sub2}    


%Sub 2: Grandmother
\arctext[N2S2][orange2][13pt](2.5)(270)(360){|\footnotesize\bf\color{white}| Sub2};

        %Sub 2-Sub 1: Great Grandfather
    \arctext[N2S2S1][orange2][8pt](3.25)(270)(315){|\footnotesize\bf\color{white}| Sub2-Sub1};

        %Sub 2-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N2S2S1S1][orange2][8pt](3.8)(270)(292.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 2-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N2S2S1S2][orange2][8pt](3.8)(292.5)(315){|\footnotesize\bf\color{white}| Sub1-Sub2}    

    %Sub 2-Sub 2: Great Grandmother
            \arctext[N2S2S2][orange2][8pt](3.25)(315)(360){|\footnotesize\bf\color{white}| Sub2-Sub2};

        %Sub 2-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N2S2S2S1][orange2][8pt](3.8)(315)(337.5){|\footnotesize\bf\color{white}| Sub1-Sub1};

        %Sub 2-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N2S2S2S2][orange2][8pt](3.8)(337.5)(360){|\footnotesize\bf\color{white}| Sub1-Sub2}    

\end{tikzpicture}


\end{document}

代码示例

答案1

您可以向宏添加第八个参数\arctext,然后在其定义中添加第二个\path带有text along path 装饰的参数。修改raise值,使它们一个在另一个之上,并可能减小字体大小。然后,不要只\arctext...{one line of text}使用 ,而是使用\arctext...{first line}{second line}

无关:我分别将\sf\bf改为\sffamily\bfseries,因为自 90 年代初以来,较短的形式已被弃用。

在此处输入图片描述

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}

\definecolor{orange1}{HTML}{F1753A}
\definecolor{orange2}{HTML}{F7A13E}
\definecolor{orange3}{HTML}{FC6300} 
\definecolor{root}{HTML}{B2B2B2}

\renewcommand*\familydefault{\sfdefault} % Set font to serif family

% arctext from Andrew code with modifications:
%Variables: 1: ID, 2:Style 3:box height 4: Radious 5:start-angl 6:end-angl 7:text {format along path} 
\def\arctext[#1][#2][#3](#4)(#5)(#6)#7#8{% <-- added #8 here

\draw[
color=white,
thick,
line width=1.3pt,
fill=#2
]
(#5:#4cm+#3) coordinate (above #1) arc (#5:#6:#4cm+#3)
-- (#6:#4) coordinate (right #1) -- (#6:#4cm-#3) coordinate (below right #1) 
arc (#6:#5:#4cm-#3) coordinate (below #1)
-- (#5:#4) coordinate (left #1) -- cycle;
\def\a#1{#4cm+#3}
\def\b#1{#4cm-#3}
\path[
decoration={
    raise = 0.1ex, % Controls relative text height position. <--- CHANGED
    text along path,
    text = {#7},
    text align = center,
    text color=white,
},
decorate
]
(#5:#4) arc (#5:#6:#4);

% added second path
\path[
decoration={
    raise = -0.9ex, % different value
    text along path,
    text = {#8}, % <-- #8 instead of #7
    text align = center,
    text color=white,
},
decorate
]
(#5:#4) arc (#5:#6:#4);
}

%arcarrow, this is mine, for beerware purpose...
%Function: Draw an arrow from arctex coordinate specific nodes to another 
%Arrow start at the start of arctext box and could be shifted to change the position
%to avoid go over another box.
%Var: 1:Start coordinate 2:End coordinate 3:angle to shift from acrtext box  
\def\arcarrow[#1](#2)(#3)[#4]{
\draw[thick,-,>=latex,color=#1,line width=1pt,shorten >=-2pt, shorten <=-2pt] 
    let \p1 = (#2), \p2 = (#3), % To access cartesian coordinates x, and y.
        \n1 = {veclen(\x1,\y1)}, % Distance from the origin
        \n2 = {veclen(\x2,\y2)}, % Distance from the origin
        \n3 = {atan2(\y1,\x1)} % Angle where acrtext starts.
    in (\n3-#4: \n1) -- (\n3-#4: \n2); % Draw the arrow.
}

\begin{document}
\begin{tikzpicture}[
    % Environment Cfg
    font=\sffamily\scriptsize,
    % Styles
    myarrow/.style={
        thick,
        -latex,
    },
    Center/.style ={
        circle,
        fill=white,
        text=root,
        align=center,
        font =\footnotesize,
        inner sep=1pt,          
    },
]

% Drawing the center
\node[Center](ROOT) at (0,0) {Test \\ Boy};

% Drawing the Tex Arcs

% \Arctext[ID][box-style][box-height](radious)(start-angl)(end-angl){|text-styles| Text}
% Node 1:  Father 
\arctext[N1][orange1][15pt](1.5)(180)(0){|\tiny\bfseries| John Boy  B. 12 Jun 2016}{|\tiny| foo bar baz};

%Sub 1: Grandfather
\arctext[N1S1][orange1][13pt](2.5)(180)(90){|\tiny\bfseries| Sub1}{|\tiny| foo bar baz};

    %Sub 1-Sub 1: Great Grandfather
    \arctext[N1S1S1][orange1][8pt](3.25)(180)(135){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N1S1S1S1][orange1][8pt](3.8)(180)(157.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N1S1S1S2][orange1][8pt](3.8)(157.5)(135){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}        

    %Sub 1-Sub 2: Great Grandmother
    \arctext[N1S1S2][orange1][8pt](3.25)(135)(90){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}

        %Sub 1-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N1S1S2S1][orange1][8pt](3.8)(135)(112.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N1S1S2S2][orange1][8pt](3.8)(112.5)(90){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}


%Sub 2: Grandmother
\arctext[N1S2][orange1][13pt](2.5)(90)(0){|\tiny\bfseries| Sub2}{|\tiny| foo bar baz};

        %Sub 2-Sub 1: Great Grandfather
    \arctext[N1S2S1][orange1][8pt](3.25)(90)(45){|\tiny\bfseries| Sub2-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N1S2S1S1][orange1][8pt](3.8)(90)(67.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N1S2S1S2][orange1][8pt](3.8)(67.5)(45){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}

    %Sub 2-Sub 2: Great Grandmother
            \arctext[N1S2S2][orange1][8pt](3.25)(45)(0){|\tiny\bfseries| Sub2-Sub2}{|\tiny| foo bar baz};

        %Sub 2-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N1S2S2S1][orange1][8pt](3.8)(45)(22.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N1S2S2S2][orange1][8pt](3.8)(22.5)(0){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz} 

\arctext[N2][orange2][15pt](1.5)(180)(360){|\tiny\bfseries| John Boy B. 12 Jun 2016}{|\tiny| foo bar baz};

%Sub 1: Grandfather
\arctext[N2S1][orange2][13pt](2.5)(180)(270){|\tiny\bfseries| Sub1}{|\tiny| foo bar baz};

    %Sub 1-Sub 1: Great Grandfather
    \arctext[N2S1S1][orange2][8pt](3.25)(180)(225){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N2S1S1S1][orange2][8pt](3.8)(180)(202.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N2S1S1S2][orange2][8pt](3.8)(202.5)(225){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}        

    %Sub 1-Sub 2: Great Grandmother
    \arctext[N2S1S2][orange2][8pt](3.25)(225)(270){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}

        %Sub 1-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N2S1S2S1][orange2][8pt](3.8)(225)(247.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 1-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N2S1S2S2][orange2][8pt](3.8)(247.5)(270){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}    


%Sub 2: Grandmother
\arctext[N2S2][orange2][13pt](2.5)(270)(360){|\tiny\bfseries| Sub2}{|\tiny| foo bar baz};

        %Sub 2-Sub 1: Great Grandfather
    \arctext[N2S2S1][orange2][8pt](3.25)(270)(315){|\tiny\bfseries| Sub2-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 1-Sub 1: Great-Great Grandfather
        \arctext[N2S2S1S1][orange2][8pt](3.8)(270)(292.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 1-Sub 2: Great-Great Grandmother
        \arctext[N2S2S1S2][orange2][8pt](3.8)(292.5)(315){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}    

    %Sub 2-Sub 2: Great Grandmother
            \arctext[N2S2S2][orange2][8pt](3.25)(315)(360){|\tiny\bfseries| Sub2-Sub2}{|\tiny| foo bar baz};

        %Sub 2-Sub 2-Sub 1: Great-Great Grandfather
        \arctext[N2S2S2S1][orange2][8pt](3.8)(315)(337.5){|\tiny\bfseries| Sub1-Sub1}{|\tiny| foo bar baz};

        %Sub 2-Sub 2-Sub 2: Great-Great Grandmother
        \arctext[N2S2S2S2][orange2][8pt](3.8)(337.5)(360){|\tiny\bfseries| Sub1-Sub2}{|\tiny| foo bar baz}    

\end{tikzpicture}


\end{document}

答案2

以下答案使用轮图包,是我写的。

弧中的文本由第一和第二个变量给出,分别用\WCvarA和表示\WCvarB。它们在键 中使用arc data。此处,\\可用于将文本拆分为多行。

\WCmidangle该文本的方向取决于键中使用的圆弧中间的角度arc data dir

此文本位于带有键的圆弧的中心arc data pos=0.5

切片之间的间隙是通过键gap和获得的gap radius

在此处输入图片描述

\documentclass[border=6pt]{standalone}
\usepackage{listofitems}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\readlist\WCcolors{orange!75,orange}
\pgfkeys{
  /wheelchart,
  arc data=\WCvarA\\\WCvarB,
  arc data dir={\WCmidangle<180?1:-1},
  arc data expand=f,
  arc data pos=0.5,
  arc data style={text color=white},
  data=,
  gap,
  gap radius,
  slices style=\WCcolors[\fpeval{\WCmidangle<180?2:1}],
  start angle=0,
  value=1
}
\wheelchart[
  middle=Test\\Boy,
  middle style=darkgray,
  radius={1}{2}
]{%
  John Boy A. 12 Jun 2016/Text A,
  John Boy B. 23 Sep 2023/Text B%
}
\wheelchart{%
  Sub1/Text1,
  Sub2/Text2,
  Sub3/Text3,
  Sub4/Text4%
}
\end{tikzpicture}
\end{document}

相关内容