代码:
\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%
ETC。
- 如何在较长文本右侧 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}