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 mm に水平線を作成するにはどうすればよいでしょうか。

ここに画像の説明を入力してください

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}

関連情報