Mit der Hilfe eines Users von texwelt.de konnte ich einen Zeilenumbruch in der tikz Umgebung realisieren. Danke! (Siehe Code)

Nun zu meiner abschließenden Frage zu dem Thema Filetree/usepackage Forest... Wie kann ich dieses Mal einen weiteren unabhängigen Node in der "gleichen Zeile" direkt auf der Verbindungslinie setzen? Der weitere Node (im Bild mit roter Schriftfarbe) besteht aus mehreren Zeichen somit müsste die Horizontale Linie auch in die Länge gezogen werden.

mein Code:

Öffne in Overleaf
\documentclass[11pt,a4paper,titlepage,bibliography=totoc,numbers=noenddot,abstract=on,multi,dvipsnames,svgnames,x11names]{scrreprt}

\usepackage{storebox}
\usepackage[edges]{forest}
\usepackage{adjustbox}

%Zeilenumbruch in der tikz Umgebung!
% addaswyd o gôd Sašo Živanović: http://tex.stackexchange.com/a/296771/
\def\hiddenparcommand{\par}
\newcommand\otherhiddenparcommand{\par\noindent}
\newcommand\hiddencommacommand{, }
\forestset{%
    declare keylist register={split here ids},% the list of nodes to split the tree at
    split here ids={},
    declare keylist register={split here interjects},% the list of comments to put in between the tree parts
    split here interjects={},
    declare keylist={split here auto siblings}{},% a list to hold the siblings which need edge restoration
    declare toks register=split here toks,
    declare dimen register=tmpdima,
    tmpdima'=0pt,
    declare dimen register=tmpdimb,
    tmpdimb'=0pt,
    declare dimen register=tmpdimc,
    tmpdimc'=0pt,
    to widest/.style={
        tikz+={\path (\forestregister{tempdima}, \forestoption{y}) -- (\forestregister{tempdimb}, \forestoption{y});},
    },
    hide commas/.style={%
        split here toks+={\hiddencommacommand},
        split here toks+={#1},
    },
    split dir tree pre/.style={%
        label={[text=gray, anchor=north, font=\scriptsize]below:{[cont.]}{}},
    },
    split dir tree post/.style={%
        label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    },
    split dir tree auto post/.style={% this gets applied to the first node after a break
        split dir tree post,
        tempkeylistc'={},
        tmpdimb/.option=y,
        for nodewalk={
            while={
                > ORw2+d _+d < On=! & {y}{tmpdimb}{##2-##1} {\textheight-#1} {n'}{1}%
            }{
                next,
                tempkeylistc/.option=name
            }%
        }{},
        % save the list
        split here auto siblings/.register=tempkeylistc,
        tikz+/.process={% this tries to redraw the edges to the following siblings
            OOw2{edge}{id}%
            {%
                \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##2) |- (.child anchor);
                \edef\tempa{\foresteoption{split here auto siblings}}
                \foreach \i in \tempa \path [##1] (before ##2) |- ({forest cs:\i.child anchor});
            }%
        },
    },
    split dir tree/.code={%
        \forestset{%
            draw tree stage/.style={
                for root'={
                    tempdima/.min={%
                        >OOw2+d{x}{min x}{####1+####2}%
                    }{tree},
                    tempdimb/.max={%
                        >OOw2+d{x}{max x}{####1+####2}%
                    }{tree},
                    for tree={%
                        to widest,
                    },
                },
                tempcountb'=-1,
                do until={%
                    strequal((split_here_ids),"")
                }{%
                    tempkeylistb'={},
                    tempkeylista'={},
                    split register={split here ids}{,}{tempcounta,tempkeylistb+},
                    split register={split here interjects}{,}{temptoksa,tempkeylista+},
                    split here ids'/.register=tempkeylistb,
                    split here interjects'/.register=tempkeylista,
                    % Sašo Živanović: http://chat.stackexchange.com/transcript/message/28484520#28484520
                    for nodewalk={%
                        draw tree processing order/.style={%
                            filter={tree}{> ORw+n< OR> & {id}{tempcounta}{########1+1}{id}{tempcountb}}%
                        }%
                    }{},
                    for root'={draw tree},
                    TeX/.process={Rw{temptoksa}{\otherhiddenparcommand ####1\hiddenparcommand}},
                    tempcountb'/.register=tempcounta,
                },
                for nodewalk={%
                    draw tree processing order/.style={%
                        filter={tree}{>OR>{id}{tempcountb}}%
                    }%
                }{},
                for root'={draw tree},
            },
        }%
    },
    split dir here auto/.style n args=2{%
        split dir tree pre,
        !next node.split dir tree auto post=#2,
        split here ids+/.option=id,
        %     !next node.split resume here ids+/.option=id,
        split={#1}{,}{split here toks,hide commas},
        split here interjects/.register=split here toks,
    },
    split dir tree auto/.style={%
        split dir tree,
        before drawing tree={%
            tempdima/.max={y}{tree},
            tempdimc/.register=tempdima,
            tempdimd/.min={y}{tree},
            tempdima-/.register=tempdimd,
            tempdimb'=\textheight,
            tmpdima'=10ex,
            tmpdimc'=\pagetotal,
            while={%
                >RR>{tempdima}{tempdimb}%
            }{%
                for nodewalk={%
                    root',
                    until={%
                        > ROw2+d RRw2+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{\textheight-##2-##1}%
                    }{next node},
                    previous node,
                    split dir here auto/.process={R_w2{tmpdima}{continued}{{##2}{##1}}},
                    next node,
                    tempdima/.option=y,
                    tempdimc/.register=tempdima,
                    tempdima-/.register=tempdimd,
                    tmpdima'=15ex,
                    tmpdimc'=0pt
                }{},
            },
        },
    },
}
%Zeilenumbruch in der tikz Umgebung! Ende

\begin{document}    
\begin{forest}
    for tree={
        folder,
        grow'=0,
        fit=band,
    },
    split dir tree auto,
    [ XYZ
    [ XYZ
    [ XYZ
    [ XYZ
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    ]
    ]
\end{forest}

\end{document}

Danke. alt text

gefragt 18 Sep '18, 16:12

helmutW's gravatar image

helmutW
116712
Akzeptiert-Rate: 40%

bearbeitet 18 Sep '18, 16:15


Fairerweise sollte man sagen, dass all das von @cfr, einem Top User von tex.stackexchange.com, kommt. Sie hat den wesentlichen Durchbruch hier erzielt, und dann das Ganze noch auf mehrspaltige Dokumente verallgemeinert. All das erfordert ein tiefes Verständnis von forest, etwas, das ich nicht besitze. Wozu ich jedoch schon imstande bin, ist edge labels nachzuschlagen: Man kann labels auf die Kanten setzen mit edge label. Wenn Du das sehr oft machen magst, bietet sich evtl. an, mit \forestset einen Style dafür zu deklarieren, wie ich das in der anderen Antwort getan habe. Und evt. magst Du die horizontalen Abstände erhöhen, damit die Labels nicht zu sehr eingeengt werden. Ich habe diese Dinge erst mal nicht eingebaut, kann das aber gerne nachholen.

Öffne in Overleaf
\documentclass[11pt,a4paper,titlepage,bibliography=totoc,numbers=noenddot,abstract=on,multi,dvipsnames,svgnames,x11names]{scrreprt}

\usepackage{storebox}
\usepackage[edges]{forest}
\usepackage{adjustbox}

%Zeilenumbruch in der tikz Umgebung!
% addaswyd o gôd Sašo Živanović: http://tex.stackexchange.com/a/296771/
\def\hiddenparcommand{\par}
\newcommand\otherhiddenparcommand{\par\noindent}
\newcommand\hiddencommacommand{, }
\forestset{%
    declare keylist register={split here ids},% the list of nodes to split the tree at
    split here ids={},
    declare keylist register={split here interjects},% the list of comments to put in between the tree parts
    split here interjects={},
    declare keylist={split here auto siblings}{},% a list to hold the siblings which need edge restoration
    declare toks register=split here toks,
    declare dimen register=tmpdima,
    tmpdima'=0pt,
    declare dimen register=tmpdimb,
    tmpdimb'=0pt,
    declare dimen register=tmpdimc,
    tmpdimc'=0pt,
    to widest/.style={
        tikz+={\path (\forestregister{tempdima}, \forestoption{y}) -- (\forestregister{tempdimb}, \forestoption{y});},
    },
    hide commas/.style={%
        split here toks+={\hiddencommacommand},
        split here toks+={#1},
    },
    split dir tree pre/.style={%
        label={[text=gray, anchor=north, font=\scriptsize]below:{[cont.]}{}},
    },
    split dir tree post/.style={%
        label={[font=\scriptsize, anchor=south, text=gray]above:{[cont.]}{}},
    },
    split dir tree auto post/.style={% this gets applied to the first node after a break
        split dir tree post,
        tempkeylistc'={},
        tmpdimb/.option=y,
        for nodewalk={
            while={
                > ORw2+d _+d < On=! & {y}{tmpdimb}{##2-##1} {\textheight-#1} {n'}{1}%
            }{
                next,
                tempkeylistc/.option=name
            }%
        }{},
        % save the list
        split here auto siblings/.register=tempkeylistc,
        tikz+/.process={% this tries to redraw the edges to the following siblings
            OOw2{edge}{id}%
            {%
                \path [##1] (!u.parent anchor |- .north) ++(\forestregister{folder indent},1ex) coordinate (before ##2) |- (.child anchor);
                \edef\tempa{\foresteoption{split here auto siblings}}
                \foreach \i in \tempa \path [##1] (before ##2) |- ({forest cs:\i.child anchor});
            }%
        },
    },
    split dir tree/.code={%
        \forestset{%
            draw tree stage/.style={
                for root'={
                    tempdima/.min={%
                        >OOw2+d{x}{min x}{####1+####2}%
                    }{tree},
                    tempdimb/.max={%
                        >OOw2+d{x}{max x}{####1+####2}%
                    }{tree},
                    for tree={%
                        to widest,
                    },
                },
                tempcountb'=-1,
                do until={%
                    strequal((split_here_ids),"")
                }{%
                    tempkeylistb'={},
                    tempkeylista'={},
                    split register={split here ids}{,}{tempcounta,tempkeylistb+},
                    split register={split here interjects}{,}{temptoksa,tempkeylista+},
                    split here ids'/.register=tempkeylistb,
                    split here interjects'/.register=tempkeylista,
                    % Sašo Živanović: http://chat.stackexchange.com/transcript/message/28484520#28484520
                    for nodewalk={%
                        draw tree processing order/.style={%
                            filter={tree}{> ORw+n< OR> & {id}{tempcounta}{########1+1}{id}{tempcountb}}%
                        }%
                    }{},
                    for root'={draw tree},
                    TeX/.process={Rw{temptoksa}{\otherhiddenparcommand ####1\hiddenparcommand}},
                    tempcountb'/.register=tempcounta,
                },
                for nodewalk={%
                    draw tree processing order/.style={%
                        filter={tree}{>OR>{id}{tempcountb}}%
                    }%
                }{},
                for root'={draw tree},
            },
        }%
    },
    split dir here auto/.style n args=2{%
        split dir tree pre,
        !next node.split dir tree auto post=#2,
        split here ids+/.option=id,
        %     !next node.split resume here ids+/.option=id,
        split={#1}{,}{split here toks,hide commas},
        split here interjects/.register=split here toks,
    },
    split dir tree auto/.style={%
        split dir tree,
        before drawing tree={%
            tempdima/.max={y}{tree},
            tempdimc/.register=tempdima,
            tempdimd/.min={y}{tree},
            tempdima-/.register=tempdimd,
            tempdimb'=\textheight,
            tmpdima'=10ex,
            tmpdimc'=\pagetotal,
            while={%
                >RR>{tempdima}{tempdimb}%
            }{%
                for nodewalk={%
                    root',
                    until={%
                        > ROw2+d RRw2+d > {tempdimc}{y}{##1-##2} {tmpdima}{tmpdimc}{\textheight-##2-##1}%
                    }{next node},
                    previous node,
                    split dir here auto/.process={R_w2{tmpdima}{continued}{{##2}{##1}}},
                    next node,
                    tempdima/.option=y,
                    tempdimc/.register=tempdima,
                    tempdima-/.register=tempdimd,
                    tmpdima'=15ex,
                    tmpdimc'=0pt
                }{},
            },
        },
    },
}
%Zeilenumbruch in der tikz Umgebung! Ende

\begin{document}    
\begin{forest}
    for tree={
        folder,
        grow'=0,
        fit=band,
    },
    split dir tree auto,
    [ XYZ
    [ XYZ
    [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{1}}
    [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{A}}
    [ XYZ,edge label={node[pos=0.75,above,font=\scriptsize]{3}} ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    ]
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    [ XYZ
    [ XYZ
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    [ XYZ ]
    ]
    ]
    ]
    ]
\end{forest}

\end{document}

alt text

Permanenter link

beantwortet 18 Sep '18, 16:45

Community's gravatar image

Community
21
Akzeptiert-Rate: 56%

@Murmeltier Danke für deine konstruktive Antwort. Oft ist das Verständnis sekundär viel wichtiger ist oft zu wissen wo man Lösungen finden kann und gegebene Lösungen zu verbinden (als Anwender) Letzte Frage: Wie kann ich die Länge der horizontale Linie der Größe des Strings anpassen? Zb: wenn der String wie folgt lautet [ XYZ,edge label={node[pos=0.75,above,font=ttfamily]{dsafs dsadasda}}

(18 Sep '18, 17:17) helmutW

@helmutW Mir ist nicht klar, ob das sehr einfach geht, bzw., ob das erstrebenswert ist. In einem tree sollen ja alle Nodes, die auf dem selben Level sind, die selbe horizontale Position haben (wenn, wie hier, der Baum nach rechts wächst). Wäre es da nicht besser, einfach global den Abstand zu erhöhen?

(18 Sep '18, 17:48) Community

@helmutW Du brauchst bloss l sep=1cm, in for tree={ eintragen. Klar, Du kannst auch etwas anderes als 1cm nehmen.

(20 Sep '18, 17:07) Community

@Murmeltier der Code funktioniert aber nur korrekt wenn der Datensatz wirklich über 1 Seite hinaus geht (Pagebreak) Wenn der Datensatz aber kürzer als 1 Seite ist dann bekomme ich eine Fehlermeldung. Was kann ich dagegen tun? Danke für deine Unterstützung.

(27 Sep '18, 17:29) helmutW
1

@helmutW Mich überkommt ein klein wenig das Gefühl, dass Du diese Site hier mit einer Service Hotline verwechselst. Du hattest mich gebeten, Labels auf die Verbindungslinien zu setzen, was ich getan habe. Mittlerweile sind wir bei der zweiten Zusatzforderung. Ich habe meine Antwort auf dem Code aufgebaut, den Du geliefert hast, und ich denke, dass ich die ursprüngliche Frage beantwortet habe. Was kommt als nächstes? Du magst unter dem Tree ein Feynman Diagram haben? Und schreibst das in einem Kommentar? Fragen sind kostenlos, und eine Frage ist eine Frage, ohne Nachkarteln.

(27 Sep '18, 21:36) Community
1

@helmutW Um es noch mal anders auszudrücken: Jeder ist willkommen hier, Fragen zu stellen. Und das ist Alles kostenlos und üblicherweise bekommt man m.E. gute Antworten. ABER: Das ist kein Service-Center, wo man, wenn man endlich mal aus der Warteschleife ist und die Mitarbeiterin/den Mitarbeiter an der Strippe hat, Frage über Frage stellt. Wenn Du mit meiner Antwort unzufrieden bist, ist es Dein gutes Recht, sie zu ignorieren. Gleichzeitig nehme ich mir heraus, jedes Addendum an Deine Frage zu ignorieren. Deswegen schreibe Deine Sonderwünsche bitte in die Frage, nicht unter meine Antwort.

(28 Sep '18, 04:16) Community

@Murmeltier Danke für deine konstruktive Antwort. Ich nehme diese Kritik zur Kenntnis. Leider ist es für mich als Laie sehr sehr schwer Latex zu verstehen. Da es meiner Meinung nach keine in einander greifende Dokumentation gibt. Für mich besteht LAtex aus vielen Brocken an Code den man erst kompliziert verbinden muss. Soll ich meine neue Frage als neue Frage posten? Danke für deine Geduld. :)

(28 Sep '18, 09:23) helmutW

@helmutW Das mag ja Alles sein. (Damit will ich sagen, dass ich sehr wohl sehen kann, dass Du das so siehst, auch wenn ich persönlich nicht 100% damit übereinstimme.) Aber wieso hindert Dich das, einfach eine neue offizielle Frage zu stellen, wenn Du eine hast? Erstens sind Fragen kostenlos. Zweitens: was ist, wenn Du die Frage an mich während des Winterschlafs stellst? Dann bleibt die bis zu 8 Monate unbeantwortet. Wenn Du sie "offiziell" stellst, sehen sie Alle, d.h. auch welche, die keinen Winterschlaf halten, und Du bekommst Deine Antwort früher. ;-)

(29 Sep '18, 04:02) Community

@helmutW Ja, weitere Fragen, auch Folgefragen, als neue Frage stellen. So ist es besser sortiert, und man sieht neue Fragen so besser als in den Kommentaren. Die sind bewusst klein und dezent gehalten. Das verbessert die Übersicht erheblich für die Archivierung der Lösungen. Ungewohnt und anders als in Webforen, doch innovativ und nutzbarer. Bemerkungen ansonsten gern als Kommentare. Kein Problem mit "einfachen" Fragen oder schwierigen, es antwortet natürlich auch nur, wer gerade Lust und Zeit hat, alles freiwillig und freundlich hier.

(29 Sep '18, 16:30) stefan ♦♦
Ergebnis 5 von 9 show 4 more comments
Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×728
×3

gestellte Frage: 18 Sep '18, 16:12

Frage wurde gesehen: 3,374 Mal

zuletzt geändert: 29 Sep '18, 16:30