Tikz: как создать линию в центре картинки справа от узла?

Tikz: как создать линию в центре картинки справа от узла?

Код:

\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}

Печать:

введите описание изображения здесь

Количество фигурных скобок может быть произвольным:

  1. 2 - 50% (в этом примере)
  2. 3 - 33%
  3. 4 - 25%

и т. д.

  1. Как создать горизонтальную линию на 1 мм правее длинного текста, расположенную по центру высоты изображения:

введите описание изображения здесь

2.Как видите, эти команды выглядят похоже:

%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\%};

Можно ли поместить тексты в массив и создать цикл, который создаст эти скобки?

решение1

Вот предложение.

Вы можете использовать что-то вроде

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

чтобы нарисовать стрелку.

TikZ имеет встроенную поддержку циклов, см. главу56 Повторяющиеся вещи в руководстве. Вероятно, есть лучшие способы сделать это, чем код ниже, но, похоже, это работает.

\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}

Связанный контент