Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am drawing a little sketch depicting an experiment (code below): enter image description here

At the arrows (under % Outgoing lines in the code) to the right I would like to place little rectangles with their long side perpendicular to each arrow (what would be even better if those rectangles were more like square brackets, i.e. unfilled rectangles with thick lines and the long side closer to the arrow not drawn). The size of such a rectangle should be just big enough so that the heads of the upper two lines can "fit" into one.

Since I have defined the arrows to have the same length and just point away from a certain central point under different angles, their end points essentially lie on a circle.

Any ideas how I can achieve what I outlined above?

\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}
share|improve this question
add comment

3 Answers

Method 1: Square Brackets:

If you simply want to add a square bracket, you can simply add a node and rotate it:

\draw[->] (2.2,0.0) -- +(45:2cm) node [rotate=45] {]};

If you want it a different size you can use scalebox:

\draw[->] (2.2,0.0) -- +(35:2cm) node [rotate=35] {\scalebox{0.5}{]}};

enter image description here


Method 1: Draw the Shape:

However, a better solution is to draw the desired shape with something like:

\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
 }

Here you can adjust the sizing of this precisely, but with the current values, this yields:

enter image description here


Code: Square Brackets

\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}

Code: Draw the Shape:

\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}
share|improve this answer
    
Instead of explicit angle declarations, you can also use pos=1,sloped option to get the automatic rotation. –  percusse Jan 29 '12 at 1:48
    
@percusse: Good idea, but don't think that that will work with the revised method (which yields much better results anyway), although might if a new shape was defined. –  Peter Grill Jan 29 '12 at 1:51
    
Ow I missed your update and you're right; but yet another approach might be a new arrow type using \pgfarrowdeclarecombine to ease the definition process. –  percusse Jan 29 '12 at 1:59
    
@percusse: An even better idea. You should do that version. –  Peter Grill Jan 29 '12 at 2:59
add comment

A small addition to Peter Grill's comprehensive answer with a new arrow type using the following:

\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}

enter image description here

The horizontal arrow bracket looks slimmer than it is shown in the pdf file for some reason.

share|improve this answer
    
I really like this solution. I do wonder though: is it possible to have the bracket arrow-head larger than latex-head? Or do I need to create a new king of arrow head for that and combine them? –  mSSM Jan 29 '12 at 20:21
    
Ha, even better! I just used a decoration for that. Going to post my result after I am done. –  mSSM Jan 29 '12 at 20:40
add comment
up vote 4 down vote accepted

I hope it's okay to just add my solution as well... I thought people might want to know what I ended up doing. But credit goes to Peter Grill and percusse, of course! ;)

As an addition to Peter Grill's and percusse's solutions, instead of explicitly drawing square brackets or combining a normal arrow with a bracket-arrow-head using \pgfarrowsdeclarecombine, I used a decoration via a postaction and got exactly what I wanted (after I also shortened my path a bit; see the code below):

    \draw[->,%
     decoration={markings,mark=at position 1 with {\arrow[scale=2.5]{]}}},%
     postaction={decorate},%
     shorten >=5\pgflinewidth%
     ] (2.2,0.0) -- +(-40:2cm);

enter image description here

I actually wanted the upper two lines to go into one bracket, so I just made a path there and drew an arrow at the end of that. Lucky me that worked without further fiddling! :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}
share|improve this answer
1  
Its absolutely ok to answer the question yourself; particularly if it offers another yet unmentioned way. You can even accept your now answer since this on ist the one you chose ;-) –  Tobi Jan 4 at 0:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.