使用 tikz 仅绘制四分之三的支架

使用 tikz 仅绘制四分之三的支架

我想只画出四分之三的括号来说明括号的延伸(见下面的示例,带标题的括号e)。我想说明该部分(用带标题的括号标记e)在左侧延伸到无穷远。

\documentclass[11pt, xcolor=dvipsnames]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}[decoration=brace]%, scale=0.85]
\draw [black,ultra thick](0,0)--(10,0);
\draw [BrickRed,ultra thick, dashed](-2,0)--(0,0);
\draw [BrickRed,ultra thick, dashed](10,0)--(12,0);
\draw [black,ultra thick](10,-0.2)--(10,0.2);
\draw [black,ultra thick](0,-0.2)--(0,0.2);

\draw[MidnightBlue, thick,decorate, yshift=2ex] (0.0,0) -- node[above=0.4ex] {a} (2,0);
\draw[MidnightBlue, thick,decorate, yshift=-2ex] (3.2,0) -- node[below=0.4ex] {b} (2,0);
\draw[MidnightBlue, thick,decorate, yshift=2ex] (3.2,0) -- node[above=0.4ex] {c} (6,0);
\draw[MidnightBlue, thick,decorate, yshift=-2ex] (10,0) -- node[below=0.4ex] {d} (6,0);
\draw[MidnightBlue, thick,decorate, yshift=-2ex] (0,0) -- node[below=0.4ex] {e} (-2,0);

\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

在此处输入图片描述

答案1

我复制了装饰的定义brace并对其进行了一些修改,使其具有一个额外的属性,该属性决定了支架在哪一侧打开。

装饰open brace有额外的键open=<side>。其默认值none相当于正常的brace。可能的选项有:

在此处输入图片描述

\documentclass{article}
\pagestyle{empty}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\newif\ifopenbraceleft
\newif\ifopenbraceright
\openbraceleftfalse
\openbracerightfalse

\pgfkeys{
  /pgf/decoration/.cd,
  open/.is choice,
  open/left/.is if = openbraceleft,
  open/right/.is if = openbraceright,
  open/both/.style = {open/left = true, open/right = true},
  open/none/.style = {open/left = false, open/right = false},
  open/.initial = none
}

\pgfdeclaredecoration{open brace}{initial}
{
  \state{initial}[width=+\pgfdecoratedremainingdistance,next state=final]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \ifopenbraceright
    \pgfpathmoveto{\pgfqpoint{0pt}{.5\pgfdecorationsegmentamplitude}}
    \else
    \pgfpathcurveto
    {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
    {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
    {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
    \fi
    {
      \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}
      \ifopenbraceleft
      \pgfpathlineto{\pgfqpoint{0pt}{.5\pgfdecorationsegmentamplitude}}
      \else
      \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{0pt}{0pt}}
      \fi
    }
  }
  \state{final}
  {}
}

\begin{document}

\begin{tikzpicture}
\draw [black,ultra thick](0,0)--(10,0);
\draw [BrickRed,ultra thick, dashed](-2,0)--(0,0);
\draw [BrickRed,ultra thick, dashed](10,0)--(12,0);
\draw [black,ultra thick](10,-0.2)--(10,0.2);
\draw [black,ultra thick](0,-0.2)--(0,0.2);

\draw[MidnightBlue,thick,decorate,decoration=brace,yshift=2ex] (0.0,0) -- node[above=0.4ex] {a} (2,0);
\draw[MidnightBlue,thick,decorate,decoration=brace,yshift=-2ex] (3.2,0) -- node[below=0.4ex] {b} (2,0);
\draw[MidnightBlue,thick,decorate,decoration=brace,yshift=2ex] (3.2,0) -- node[above=0.4ex] {c} (6,0);
\draw[MidnightBlue,thick,decorate,decoration=brace,yshift=-2ex] (10,0) -- node[below=0.4ex] {d} (6,0);
\draw[MidnightBlue,thick,decorate,decoration={open brace,open=left},yshift=-2ex] (0,0) -- node[below=0.4ex] {e} (-2,0);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容