我正在画一个描绘实验的小草图(代码如下):
在右侧的箭头处(代码中 % 传出行下方),我想放置一些小矩形,其长边垂直于每个箭头(如果这些矩形更像方括号,即未填充的矩形,线条较粗,长边靠近未绘制的箭头,那就更好了)。这种矩形的大小应该足够大,以便上面两行的头部可以“容纳”到一个矩形中。
由于我已将箭头定义为具有相同的长度并且只是以不同的角度指向某个中心点,因此它们的端点基本上位于一个圆上。
有什么想法可以让我实现上面概述的目标吗?
\documentclass[article]
\usepackage{tikz}
\usetikzlibrary[patterns]
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines] (-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines
\draw[->] (2.2,0.0) -- +(45:2cm);
\draw[->] (2.2,0.0) -- +(35:2cm);
% Area element
\draw[<->] (2.2,0.0) +(35:1.5cm) arc [start angle=35,delta angle=10,radius=1.5cm];
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[->] (2.2,0.0) -- +(0:2cm);
\draw[->] (2.2,0.0) -- +(-45:2cm);
\end{tikzpicture}
\end{document}
\usepackage{tikz}
\usetikzlibrary[patterns]
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines] (-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines
\draw[->] (2.2,0.0) -- +(45:2cm);
\draw[->] (2.2,0.0) -- +(35:2cm);
% Area element
\draw[<->] (2.2,0.0) +(35:1.5cm) arc [start angle=35,delta angle=10,radius=1.5cm];
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[->] (2.2,0.0) -- +(0:2cm);
\draw[->] (2.2,0.0) -- +(-45:2cm);
\end{tikzpicture}
\end{document}
答案1
方法 1:方括号:
如果您只是想添加方括号,您可以简单地添加一个节点并旋转它:
\draw[->] (2.2,0.0) -- +(45:2cm) node [rotate=45] {]};
如果你想要不同的尺寸,你可以使用scalebox
:
\draw[->] (2.2,0.0) -- +(35:2cm) node [rotate=35] {\scalebox{0.5}{]}};
方法 1:绘制形状:
但是,更好的解决方案是使用类似以下方法绘制所需的形状:
\newcommand{\DrawBrac}[2][]{%
\draw [red, thick, #1] #2% Start at given coordinate
++(-0.5ex, 0.5ex) -- ++( 0.5ex, 0.0ex)% Top Horizontal Line
-- ++( 0.0ex,-1.0ex)% Vertical Line
-- ++(-0.5ex, 0.0ex)% Bottom Horizontal Line
}
在这里,您可以精确调整其大小,但使用当前值,可以得到以下结果:
代码:方括号
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary[patterns]
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines] (-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines
\draw[->] (2.2,0.0) -- +(45:2cm) node [red,rotate=45] {]};
\draw[->] (2.2,0.0) -- +(35:2cm) node [red,rotate=35,line width=8pt] {]};
% Area element
\draw[<->] (2.2,0.0) +(35:1.5cm) arc [start angle=35,delta angle=10,radius=1.5cm] ;
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[->] (2.2,0.0) -- +(0:2cm) node [red,rotate=0] {]};
\draw[->] (2.2,0.0) -- +(-45:2cm) node [red,rotate=-45] {]};
\end{tikzpicture}
\end{document}
代码:绘制形状:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\newcommand{\DrawBrac}[2][]{%
\draw [red, thick, #1] #2% Start at given coordinate
++(-0.5ex, 0.5ex) -- ++( 0.5ex, 0.0ex)% Top Horizontal Line
-- ++( 0.0ex,-1.0ex)% Vertical Line
-- ++(-0.5ex, 0.0ex)% Bottom Horizontal Line
}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines] (-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines
\draw[->] (2.2,0.0) -- +(45:2cm) coordinate (A);
\DrawBrac[rotate=45]{(A)};
%\draw[red, thick,rotate=45] (A) ++(-0.5ex,0.5ex) -- ++(0.5ex,0.0ex) -- ++(0.0ex,-1.0ex) -- ++(-0.5ex,0.0ex);
\draw[->] (2.2,0.0) -- +(35:2cm) coordinate (B);
\DrawBrac[rotate=35]{(B)};
% Area element
\draw[<->] (2.2,0.0) +(35:1.5cm) arc [start angle=35,delta angle=10,radius=1.5cm] ;
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[->] (2.2,0.0) -- +(0:2cm) coordinate (C);
\DrawBrac{(C)};
\draw[->] (2.2,0.0) -- +(-45:2cm) coordinate (D);
\DrawBrac[rotate=-45]{(D)};
\end{tikzpicture}
\end{document}
答案2
对 Peter Grill 的全面答案进行了小小的补充,增加了一种新的箭头类型,如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns,arrows}
\begin{document}
\pgfarrowsdeclarecombine*[-2\pgflinewidth]{latbrac}{latbrac}{latex}{latex}{[}{]}%
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines](-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines
\draw[-latbrac] (2.2,0.0) -- +(45:2cm) ;
\draw[-latbrac] (2.2,0.0) -- +(35:2cm) ;
% Area element
\draw[<->] (2.2,0.0) +(35:1.5cm) arc [start angle=35,delta angle=10,radius=1.5cm] ;
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[-latbrac] (2.2,0.0) -- +(0:2cm) ;
\draw[-latbrac] (2.2,0.0) -- +(-45:2cm);
\end{tikzpicture}
\end{document}
pdf
由于某种原因,水平箭头括号看起来比文件中显示的要细。
答案3
我希望也可以添加我的解决方案...我想人们可能想知道我最后做了什么。但当然,功劳要归功于 Peter Grill 和 percusse!;)
作为 Peter Grill 和 percusse 的解决方案的补充,我没有明确绘制方括号或使用将普通箭头与括号箭头组合\pgfarrowsdeclarecombine
,而是通过后期动作使用了装饰并得到了我想要的结果(在我还缩短了路径之后;参见下面的代码):
\draw[->,%
decoration={markings,mark=at position 1 with {\arrow[scale=2.5]{]}}},%
postaction={decorate},%
shorten >=5\pgflinewidth%
] (2.2,0.0) -- +(-40:2cm);
我其实想让上面两行放在一个括号里,所以我只是在那里创建了一条路径,并在路径的末尾画了一个箭头。幸运的是,我不用再摆弄它就成功了!:D
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns,arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}
% Beam, upper border
\fill[draw opacity=0,pattern color=gray,pattern=horizontal lines] (-2,0.8) rectangle (2,-0.8);
% Beam direction
\draw[->,thick] (-1.5,0) -- (1.5,0);
\draw[latex-] (1.0,0.5) -- ++(80:1.5cm) node[right]{Beam};
% Slit, uppper part
\fill[black] (-0.125,3) rectangle (0.125,0.8);
% Slit, lower part
\fill[black] (-0.125,-0.8) rectangle (0.125,-3);
% Target
\draw[pattern=north east lines] (1.9,0.7) rectangle (2.1,-0.7);
\draw[latex-] (2.0,-0.7) -- ++(260:1.5cm) node[right]{Target};
% Outgoing lines and brackets/detectors
\draw[->, shorten >=5\pgflinewidth] (2.2,0.0) -- +(44:2cm);
\path[decoration={markings,mark=at position 1 with{\arrow[scale=2.5]{]}}},%
postaction={decorate},%
shorten >=\pgflinewidth%
] (2.2,0.0) -- +(40:2cm);
\draw[->, shorten >=5\pgflinewidth] (2.2,0.0) -- +(36:2cm);
% Area element
\draw[<->] (2.2,0.0) +(36:1.5cm) arc [start angle=36,delta angle=8,radius=1.5cm];
\draw[-latex] (2.2,0.0) ++(38:1.5cm) ++(0cm,1cm) node[above]{$d$} -- ++(0cm,-0.95cm);
\draw[->,%
decoration={markings,mark=at position 1 with {\arrow[scale=2.5]{]}}},%
postaction={decorate},%
shorten >=5\pgflinewidth%
] (2.2,0.0) -- +(0:2cm);
\draw[->,%
decoration={markings,mark=at position 1 with {\arrow[scale=2.5]{]}}},%
postaction={decorate},%
shorten >=5\pgflinewidth%
] (2.2,0.0) -- +(-40:2cm);
\end{tikzpicture}
\end{document}