播放代码

播放代码

tikz 支架似乎分三个阶段绘制(不一定按此顺序):

  • 两端的“卷曲”。
  • 中间的“点”。
  • 并有一条直线连接“点”和任一“卷曲”段。

这使得创建具有与长支架相同幅度的短支架变得困难,因为这三个阶段太宽并且最终相互重叠:

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

\begin{document}

\begin{tikzpicture}
\draw [decorate,decoration={brace,mirror,amplitude=10pt}]
    (0,0) -- (6,0) node [midway,yshift=-0.25in] {Text};
\end{tikzpicture}

\begin{tikzpicture} %% this fails; perhaps I need to xscale?
\draw [decorate,decoration={brace,mirror,amplitude=10pt}]
    (0,0) -- (0.5,0) node [midway,yshift=-0.25in] {Text};
\end{tikzpicture}

\begin{tikzpicture} %% but this is not as expected, either
\draw [xscale=1/12,decorate,decoration={brace,mirror,amplitude=10pt}]
    (0,0) -- (6,0) node [midway,yshift=-0.25in] {Text};
\end{tikzpicture}

\end{document}

在此处输入图片描述


是否可以正确缩短这个括号,同时保持振幅并且不缩放文本?

(我想我还会考虑在这么小的宽度下不会出现这些错误的替代装饰......)

答案1

使用后添加此项decorations.pathreplacing。如有必要,它将缩放支架。

\makeatletter
    \let\pgf@decorate@@brace@brace@code@old\pgf@decorate@@brace@brace@code
    \def\pgf@decorate@@brace@brace@code{
        \ifdim\pgfdecoratedremainingdistance<4\pgfdecorationsegmentamplitude
            \pgftransformxscale{\pgfdecoratedremainingdistance/4\pgfdecorationsegmentamplitude}
            \pgfdecoratedremainingdistance=4\pgfdecorationsegmentamplitude
        \fi
        \pgf@decorate@@brace@brace@code@old
    }
\makeatother

播放代码

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\makeatletter
    \let\pgf@decorate@@brace@brace@code@old\pgf@decorate@@brace@brace@code
    \def\pgf@decorate@@brace@brace@code{
        \ifdim\pgfdecoratedremainingdistance<4\pgfdecorationsegmentamplitude
            \pgftransformxscale{\pgfdecoratedremainingdistance/4\pgfdecorationsegmentamplitude}
            \pgfdecoratedremainingdistance=4\pgfdecorationsegmentamplitude
        \fi
        \pgf@decorate@@brace@brace@code@old
    }
\makeatother

\foreach\t in{10,20,...,360}{
    \tikz{
        \path(-1,-2)(3,1);
        \pgfmathsetmacro\x{1.1+sin(\t)}
        \pgfmathsetmacro\y{.1*cos(\t)}
        \pgfmathsetmacro\a{10+8*cos(\t)}
        \draw[decorate,decoration={brace,mirror,amplitude=\a pt}]
            (0,0)--
            node [yshift=-5-\a pt] {Text}
            (\x,\y);
    }
}
\end{document}

相关内容