Tikz 中的 Underbrace

Tikz 中的 Underbrace

我试图在 tikz 中向图形添加下划线,但当我编译运行 PDFLaTeX 并查看 PDF 时,下划线看起来不正确。它不是在末端向下向内卷曲,而是向外延伸然后向内形成一条水平线?我尝试过使用这里建议的其他方法,但我发现的唯一另一种方法是使用蛇形线,而且没有用。

\documentclass[a4paper,fleqn]{article}
\usepackage{amssymb,amsthm,tikz,fancyhdr,cancel,enumerate,array,booktabs,setspace,pgf,tikz,fancyhdr,graphicx,color}
\usepackage[T1]{fontenc}
\usetikzlibrary{patterns,arrows,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.6091370558375635cm,y=0.9589041095890412cm]
\draw[->,color=black] (-1,0) -- (18.7,0);
\foreach \x in {-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}
\draw[shift={(\x,0)},color=black] (0pt,-2pt);
\draw[color=black] (18.05,0.05) node [anchor=south west] { Time};
\draw[->,color=black] (0,-1) -- (0,6.3);
\foreach \y in {-1,1,2,3,4,5,6}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\draw[color=black] (0.09,6.04) node [anchor=west] { Stock Level};
\clip(-1,-1) rectangle (18.7,6.3);
\draw (0,3)-- (3,0);
\draw (4.5,3)-- (3,0);
\draw (4.5,3)-- (7.5,0);
\draw (7.5,0)-- (9,3);
\draw (9,3)-- (12,0);
\draw (13.5,3)-- (12,0);
\draw (0,3)-- (5,3);
\draw (6.4,4.78) node[anchor=north west] {$gradient=r_s-r_d$};
\draw (10.22,4.76) node[anchor=north west] {$gradient=-r_d$};
\draw [->] (7.43,4.29) -- (8.66,2.32);
\draw [->] (11.01,4.26) -- (9.76,2.33);
\draw (-0.45,4.79) node[anchor=north west] {$Q$};
\draw (-0.5,3.36) node[anchor=north west] {$q$};
\draw (2.5,5)-- (7.5,0);
\draw (3,0)-- (3,5);
\draw (0,4.5)-- (3.5,4.5);
\draw (13.5,3)-- (16.5,0);
\draw (16.5,0)-- (18,3);
\draw (18,3)-- (21,0);
\draw [decorate,decoration={brace,amplitude=-10pt},xshift=0.4pt,yshift=-0.4pt](3,0) -- (7.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $t$};
\draw [decorate,decoration={brace,amplitude=-10pt},xshift=0.4pt,yshift=-0.4pt](12,0) -- (13.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $\frac{q}{r_s-r_d}$};
\draw [decorate,decoration={brace,amplitude=-10pt},xshift=0.4pt,yshift=-0.4pt](13.5,0) -- (16.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $\frac{q}{r_s}$};
\end{tikzpicture}
\end{document}

答案1

如果您使用正数amplitudemirror选项,那么您将获得正确的括号(添加颜色):

在此处输入图片描述

笔记:

  • 正如查尔斯·斯塔茨 (Charles Staats) 指出的那样,另一种选择是使用正长度,并反转指定坐标的顺序 - 那么您就不需要该mirror选项。

代码:

\documentclass[a4paper,fleqn]{article}
\usepackage{amssymb,amsthm,tikz,fancyhdr,cancel,enumerate,array,booktabs,setspace,pgf,tikz,fancyhdr,graphicx,color}
\usepackage[T1]{fontenc}
\usetikzlibrary{patterns,arrows,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.6091370558375635cm,y=0.9589041095890412cm]
\draw[->,color=black] (-1,0) -- (18.7,0);
\foreach \x in {-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}
\draw[shift={(\x,0)},color=black] (0pt,-2pt);
\draw[color=black] (18.05,0.05) node [anchor=south west] { Time};
\draw[->,color=black] (0,-1) -- (0,6.3);
\foreach \y in {-1,1,2,3,4,5,6}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\draw[color=black] (0.09,6.04) node [anchor=west] { Stock Level};
\clip(-1,-1) rectangle (18.7,6.3);
\draw (0,3)-- (3,0);
\draw (4.5,3)-- (3,0);
\draw (4.5,3)-- (7.5,0);
\draw (7.5,0)-- (9,3);
\draw (9,3)-- (12,0);
\draw (13.5,3)-- (12,0);
\draw (0,3)-- (5,3);
\draw (6.4,4.78) node[anchor=north west] {$gradient=r_s-r_d$};
\draw (10.22,4.76) node[anchor=north west] {$gradient=-r_d$};
\draw [->] (7.43,4.29) -- (8.66,2.32);
\draw [->] (11.01,4.26) -- (9.76,2.33);
\draw (-0.45,4.79) node[anchor=north west] {$Q$};
\draw (-0.5,3.36) node[anchor=north west] {$q$};
\draw (2.5,5)-- (7.5,0);
\draw (3,0)-- (3,5);
\draw (0,4.5)-- (3.5,4.5);
\draw (13.5,3)-- (16.5,0);
\draw (16.5,0)-- (18,3);
\draw (18,3)-- (21,0);
\draw [thick, red,decorate,decoration={brace,amplitude=10pt,mirror},xshift=0.4pt,yshift=-0.4pt](3,0) -- (7.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $t$};
\draw [thick, blue,decorate,decoration={brace,amplitude=5pt,mirror},xshift=0.4pt,yshift=-0.4pt](12,0) -- (13.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $\frac{q}{r_s-r_d}$};
\draw [thick, brown, decorate,decoration={brace,amplitude=10pt,mirror},xshift=0.4pt,yshift=-0.4pt](13.5,0) -- (16.5,0) node[black,midway,yshift=-0.6cm] {\footnotesize $\frac{q}{r_s}$};
\end{tikzpicture}
\end{document}

答案2

使用 PSTricks。

在此处输入图片描述

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-node,pst-plot}

\psset{nodesep=5pt,arm=7pt,linearc=5pt}

\def\V#1#2{\rput(#1,0){\psline(-0.5,1)(0,0)(0.5,1)\pnode(0,0){#2}}}

\def\Brace#1#2#3{%
    \pnode[0,-24pt](!\psGetNodeCenter{#1}\psGetNodeCenter{#2} #1.x #2.x add 2 div 0){center}
    \ncdiag[angleA=-80,angleB=90]{#1}{center}
    \ncdiag[angleA=90,angleB=-100]{center}{#2}
    \rput[t](center|0,-24pt){#3}
}

\begin{document}
\begin{pspicture}[showgrid=false](-0.5,-2)(10,2)
    \psaxes[labels=none]{->}(0,0)(-0.25,-1.5)(9.25,1.75)[time,0][Energy,90]
    \V{1}{A}\psline(A)(A|0,1)
    \V{3}{B}
    \Brace{A}{B}{$t$}
    \V{5}{C}
    \pnode(6,0){D}
    \Brace{C}{D}{$\frac{q}{r_s-r_d}$}
    \V{8}{E}
    \Brace{D}{E}{$\frac{q}{r_s}$}
\end{pspicture}
\end{document}

动画版

在此处输入图片描述

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-node,pst-plot}

\def\V#1#2{\rput(#1,0){\psline(-0.5,1)(0,0)(0.5,1)\pnode(0,0){#2}}}

\def\Brace#1#2#3{%
    \pnode[0,-24pt](!\psGetNodeCenter{#1}\psGetNodeCenter{#2} #1.x #2.x add 2 div 0){center}
    \ncdiag[angleA=-80,angleB=90,nodesep=5pt,arm=7pt,linearc=5pt]{#1}{center}
    \ncdiag[angleA=90,angleB=-100,nodesep=5pt,arm=7pt,linearc=5pt]{center}{#2}
    \rput[t](center|0,-24pt){#3}
}
\usepackage{multido}

\def\Picture#1{%
\begin{pspicture}[showgrid=false](-0.5,-2)(10,2)
    \psaxes[labels=none]{->}(0,0)(-0.25,-1.5)(9.25,1.75)[time,0][Energy,90]
    \V{1}{A}\psline(A)(A|0,1)
    \V{3}{B}
    \Brace{A}{B}{$t$}
    \V{5}{C}
    \pnode(#1,0){D}
    \Brace{C}{D}{$\frac{q}{r_s-r_d}$}
    \V{8}{E}
    \Brace{D}{E}{$\frac{q}{r_s}$}
\end{pspicture}}

\begin{document}
\multido{\n=5.75+0.15}{10}{\Picture{\n}}
\multido{\n=6.95+-0.15}{8}{\Picture{\n}}
\end{document}

相关内容