Tikz: Wie erstelle ich eine Linie in der Bildmitte rechts von einem Knoten?

Tikz: Wie erstelle ich eine Linie in der Bildmitte rechts von einem Knoten?

Code:

\documentclass[12pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, calc, decorations.pathreplacing,}
\begin{document}
\newlength{\distance}
\setlength{\distance}{0.6cm}
\begin{tikzpicture}[node distance = 1cm, auto]
\tikzset{
    block/.style = {rectangle, draw, text centered},
    brace/.style = {decorate,decoration={brace,amplitude=4pt}},
    caption/.style = {black, midway, xshift = 1mm},
}
\count0=0
\node [block, minimum height=2\distance] (\the\count0) {100\%};

\count1=\count0
\advance\count0 by 1
\draw [brace] (\the\count1.north east) -- 
    ($(\the\count1.north east) + (0, -\distance)$) node [caption] (\the\count0) {50\%};

\advance\count0 by 1
\draw [brace] ($(\the\count1.north east) + (0, -\distance)$) --
    ($(\the\count1.north east) + (0, -2\distance)$) node [caption] (\the\count0) 
    {longer text 50\%};

\end{tikzpicture}
\end{document}

Drucke:

Bildbeschreibung hier eingeben

Es kann eine beliebige Anzahl Klammern geben:

  1. 2 - 50 % (in diesem Beispiel)
  2. 3 - 33 %
  3. 4 - 25 %

usw.

  1. Wie kann ich eine waagerechte Linie 1mm rechts neben dem längeren Text erstellen, die sich mittig auf der Bildhöhe befindet:

Bildbeschreibung hier eingeben

2.Wie Sie sehen, sehen diese Befehle ähnlich aus:

%1
\advance\count0 by 1
\draw [brace] (\the\count1.north east) -- 
    ($(\the\count1.north east) + (0, -\distance)$) node [caption] (\the\count0) {50\%};

%2
\advance\count0 by 1
\draw [brace] ($(\the\count1.north east) + (0, -\distance)$) --
    ($(\the\count1.north east) + (0, -2\distance)$) node [caption] (\the\count0) 
    {longer text 50\%};

Ist es möglich, die Texte in ein Array einzufügen und eine Schleife zu erstellen, die diese Klammern erzeugt?

Antwort1

Hier ist ein Vorschlag.

Sie können etwas wie verwenden

\draw [-latex] (current bounding box.east) ++(1mm,0) -- +(2cm,0);

um den Pfeil zu zeichnen.

TikZ hat integrierte Unterstützung für Loops, siehe Kapitel56 Dinge wiederholen im Handbuch. Es gibt wahrscheinlich bessere Möglichkeiten, dies zu tun, als den folgenden Code, aber es scheint zu funktionieren.

\documentclass[12pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, calc, decorations.pathreplacing}
\begin{document}
\newlength{\distance}%
\setlength{\distance}{.6cm}%
\begin{tikzpicture}[node distance = 1cm, auto]
\tikzset{
    block/.style = {rectangle, draw, text centered},
    brace/.style = {decorate,decoration={brace,amplitude=4pt}},
    caption/.style = {black, midway, xshift = 1mm},
}

\pgfmathsetmacro\Nbraces{3}
\pgfmathtruncatemacro\Npercent{1/\Nbraces*100}


\node [block, minimum height=\Nbraces\distance] (mybox) {100\%};


\foreach [count=\i] \x  in {\Npercent\%,longer text \Npercent\%,\Npercent\% something else}
  \draw [brace]
    ($(mybox.north east) + {(\i-1)}*(0,-\distance)$) -- 
    ($(mybox.north east) + \i*(0,-\distance)$) node [caption] {\x};


\draw [-latex] (current bounding box.east) ++(1mm,0) -- +(2cm,0);

\end{tikzpicture}
\end{document}

verwandte Informationen