是否可以将花括号以箭头结尾?

是否可以将花括号以箭头结尾?

在下面的 MWE 中,我想将括号的右端设为指向右侧的箭头,箭头的头与下面的线一样。可以吗?

目标是使括号的右侧水平指向右侧,就像其下方的线一样。

\documentclass[a4paper,12pt]{article}
\usepackage{tikz,tikz-cd}
\usetikzlibrary{decorations.pathreplacing}
\pagestyle{empty}
\begin{document}
\begin{center}
    \begin{tikzpicture}
        \draw [->] (0,0) -- (10,0);
        \draw (0,0.2) -- (0,-0.2);
        \draw (1.5,0.2) -- (1.5,-0.2);
        \draw (3,0.2) -- (3,-0.2);
        \draw (4.5,0.2) -- (4.5,-0.2);
        \node [below] at (0,-0.2) {0};
        \node [below] at (1.5,-0.2) {1};
        \node [below] at (3,-0.2) {2};
        \node [below] at (4.5,-0.2) {3};
        \node [above] at (1.6,0.2) {\$1500};
        \node [above] at (3,0.2) {\$1500};
        \node [above] at (4.5,0.2) {\$1500};
        \draw [decorate,decoration={brace,amplitude=10pt}] (0,0.7) to (10,0.7);
        \node at (5,1.2) {simple ordinary annuity};
        \node at (4,1.8) {$j_1=6\%$};
    \end{tikzpicture}
\end{center}
\end{document}

答案1

用肮脏的方法来理顺结局。

\documentclass[a4paper,12pt]{article}
\usepackage{tikz,tikz-cd}
\usetikzlibrary{decorations.pathreplacing}
\pagestyle{empty}

\begin{document}
    \begin{center}
        \begin{tikzpicture}
        \draw [->] (0,0) -- (10,0);
        \draw (0,0.2) -- (0,-0.2);
        \draw (1.5,0.2) -- (1.5,-0.2);
        \draw (3,0.2) -- (3,-0.2);
        \draw (4.5,0.2) -- (4.5,-0.2);
        \node [below] at (0,-0.2) {0};
        \node [below] at (1.5,-0.2) {1};
        \node [below] at (3,-0.2) {2};
        \node [below] at (4.5,-0.2) {3};
        \node [above] at (1.6,0.2) {\$1500};
        \node [above] at (3,0.2) {\$1500};
        \node [above] at (4.5,0.2) {\$1500};
        \begin{scope}
        \clip(9, 1.5) rectangle (-1, -0.5);
        \draw [decorate,decoration={brace,amplitude=10pt}] (0,0.7) to (10,0.7);
        \end{scope}
        \draw[->] ([yshift=5pt]9, 0.7) -- ([yshift=5pt]10,0.7);
        \node at (5,1.2) {simple ordinary annuity};
        \node at (4,1.8) {$j_1=6\%$};
        \end{tikzpicture}
    \end{center}
\end{document} 

生成结果:

支撑

这是你想要的吗?

答案2

一种方法是使用此选项重新定义装饰,或者可以使用添加箭头作为装饰来嵌套装饰markings

    % with \usetikzlibrary{decorations.markings} in the preamble
    \draw[postaction=decorate,
         decoration={markings,mark=at position 1 with {\arrow[blue]{>}}}
         ]
          decorate[decoration={brace,amplitude=10pt}]{ (0,0.7) to (10,0.7)};

在此处输入图片描述

你也可以砍掉现有的装饰,取消最后的弯曲部分

\pgfdeclaredecoration{half brace}{brace}
{%
  \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
  {%
    \pgfpathmoveto{\pgfpointorigin}%
    \pgfpathcurveto%
    {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}%
    {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
    {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
    {%
      \pgftransformxshift{+\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance}%
      \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
      \pgfpathcurveto%
      {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
      {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}%
      {\pgfqpoint{0\pgfdecorationsegmentamplitude}{1\pgfdecorationsegmentamplitude}}%
      \pgfpathcurveto%
      {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}%
      {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
      {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}%
    }%
    {%
      \pgftransformxshift{+\pgfdecoratedremainingdistance}%
      \pgfpathlineto{\pgfqpoint{0pt}{.5\pgfdecorationsegmentamplitude}}%
    }%
  }%
  \state{final}{}%
}

如果你将它放在你的序言中,你可以half brace像使用常规一样使用它brace

\begin{tikzpicture}
        \draw [decorate,decoration={half brace,amplitude=10pt}] (0,0.7) to (10,0.7);
\end{tikzpicture}

答案3

在此处输入图片描述

按照 percusse 的回答,你可以做类似的事情

\documentclass{article}  
\usepackage{tikz}
\usetikzlibrary{decorations.markings,decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0,0.0) rectangle(9.5,2.0);
\draw [decorate,decoration={brace,amplitude=10pt}] (0,0.7) to (10,0.7);
\end{scope}
\path[postaction=decorate,decoration={markings,mark=at position 0.95 with {\arrow{>}}}] decorate[decoration={brace,amplitude=10pt}] { (0,0.7) to (10,0.7)};
\end{tikzpicture}
\end{document}

答案4

这个答案的目的只是为了表明可以使用现有的括号装饰来实现这一点。对于一个简单的任务来说,这个解决方案过于复杂了。

其他答案中的剪辑确实是一种肮脏的做法。可以用重写括号修饰,\pgfdeclaredecoration但这又太复杂了。我相信最好的选择就是根本不使用括号修饰。只需用曲线和线条绘制所需的内容即可。


\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%
\tikzset {decoration={show path construction,
    lineto code={\draw (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);},
    curveto code={
      \draw [->] (\tikzinputsegmentfirst) --
      (\tikzinputsegmentfirst -| \tikzinputsegmentlast) ;},
}};
\path[decorate, decoration={brace, amplitude=0.5cm},
postaction={
  draw,
  decorate,
  decoration={curveto, post=show path construction, post length=1cm}
}
] (0,0) -- (4,0);
%
\end{tikzpicture}
\end{document}

末端带有水平箭头的括号

相关内容