我正在尝试绘制比引用对象稍长的花括号。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\begin{document}
\tikzstyle{sensor}=[draw, text width=7em,
text centered, minimum height=2.5em]
\begin{tikzpicture}
\path (0,0) node (box1) [sensor] {Box 1};
\draw[decoration={brace,raise=15pt},decorate]
(box1.west) -- node[above=15pt] {$y$} (box1.east);
\end{tikzpicture}
\end{document}
在上面的例子中,我希望括号比盒子的边缘宽几点。
我已尝试对每个节点 +(-.2,0),但只在左侧有效。
答案1
像这样?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\begin{document}
\tikzstyle{sensor}=[draw, text width=7em,
text centered, minimum height=2.5em]
\begin{tikzpicture}
\path (0,0) node (box1) [sensor] {Box 1};
\draw[decoration={brace,raise=15pt},decorate]
([xshift=-2pt]box1.west) -- node[above=15pt] {$y$} ([xshift=2pt]box1.east);
\end{tikzpicture}
\end{document}
答案2
另一个版本:在 Tikz 中使用更长花括号的不同方法。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture} [baseline=1.2in]
\draw [thick] (0,0) -- (4,0) -- (4,2) -- (0,2) -- (0,0) ;
\draw [thick, decorate,decoration={brace,amplitude=10pt},yshift=2pt] (-.5,1.9) -- (4.5,1.9) node [black,midway,yshift=16pt] {$y$};
\node[draw=white] at (2,1) {Box 1};
\end{tikzpicture}
\end{document}