有没有办法用 tikz 获得看起来更像这样的花括号?
目前我正在使用以下方法来获取花括号:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\usetikzlibrary{decorations.pathreplacing}
\draw[decorate,decoration={brace,amplitude=0.75cm}] (0,0) -- (1,0);
\draw[decorate,decoration={brace] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
但结果是:
关键是我需要一种短花括号,其幅度有点大,但仍然看起来像括号。
答案1
这是一个原始的元修饰,但它不像标准那样通用,brace
例如raise,mirror
等将不起作用。但是,括号幅度和其他本地brace
选项已传递,并且将可用,正如我尝试在下面显示的那样。新的加注金额由键控制meta-amplitude
。
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\pgfdeclaremetadecoration{raisedbrace}{initial}{%
\state{initial}[width=\pgfmetadecoratedpathlength]{%
\decoration{brace}%
\pgfsetdecorationsegmenttransformation{%
\pgftransformyshift{\pgfmetadecorationsegmentamplitude}%
}
\beforedecoration{
\pgfpathmoveto{\pgfpointmetadecoratedpathfirst}
\pgfpathlineto{\pgfpointadd{%
\pgfpointmetadecoratedpathfirst%
}{%
\pgfpointpolar{\pgfdecoratedangle+90}{\pgfmetadecorationsegmentamplitude}%
}%
}%
}%
\afterdecoration{%
\pgfpathlineto{\pgfpointmetadecoratedpathlast}%
\pgfusepath{stroke}
}
}
}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (-1,-1) grid[step=1cm] (3,3);
\draw[decorate,decoration={raisedbrace,amplitude=2mm,meta-amplitude=4mm}] (0,1) -- (2,2);
\draw[decorate,decoration={raisedbrace,amplitude=4mm,meta-amplitude=1cm}] (0,-1) -- (2,-0.5);
\draw[decorate,decoration={raisedbrace,amplitude=1cm,meta-amplitude=5mm}] (2,3) -- (2,-0.5);
\end{tikzpicture}
\end{document}
答案2
这应该可以帮助你:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw [decorate,decoration={brace,amplitude=10pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (5.0,0.5) node [black,midway,xshift=-0.6cm]
{};
\node at (2.65,1.0) {text};
\end{tikzpicture}
\end{document}
括号的长度可以通过\draw
命令中的值来改变(0.5,0.5) -- (5.0,0.5)
。同样,文本的位置也需要改变。
更新
改变振幅,我们得到如下结果:
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw [decorate,decoration={brace,amplitude=14pt},xshift=-4pt,yshift=0pt]
(0.5,0.5) -- (5.0,0.5) node [black,midway,xshift=-0.6cm]
{};
\node at (2.65,1.2) {text};
\end{tikzpicture}
\end{document}