
암호:
\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}
인쇄물:
임의의 개수의 중괄호가 있을 수 있습니다.
- 2 - 50%(이 예에서는)
- 3~33%
- 4 - 25%
등.
- 그림 높이 중앙에 있는 긴 텍스트 오른쪽 1mm에 수평선을 어떻게 만들 수 있습니까?
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}