将标签放置在括号上方

将标签放置在括号上方

我想将其放置22在括号上方的“适当”位置。使用节点将数字与括号关联不会默认将数字放在括号的尖端。这是为什么?!

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}



\begin{document}

\begin{tikzpicture}

%A is the vertex of an angle of 55 degrees; the sides of this angle are AB
%and AC. $AB = 22$ and $AC = 13$.
\coordinate (A) at (0,0);
\node (vertex_A) at ($(A) + (82.5:7.5pt)$){$A$};
\coordinate (B) at (235:5.5);
\node (vertex_B) at ($(B) + (225:7.5pt)$){$B$};
\coordinate (C) at (290:3.25);
\node (vertex_C) at ($(C) + (-45:7.5pt)$){$C$};
\draw[name path=AB] (A) -- (B);
\draw[name path=AC] (A) -- (C);
\draw[name path=BC] (B) -- (C);

\path pic[draw, angle radius=5mm,"$\scriptstyle{55}$",angle eccentricity=1.5] {angle = B--A--C};

%These commands label the length of AC.
\coordinate (AC_midpoint) at ($(A)!0.5!(C)$);
\node (AC_midpoint_label) at ($(AC_midpoint) + (20:7.5pt)$) {$\scriptstyle{13}$};


%These commands put a brace above line segment AB and label the length `22`.  First, coordinates A' and B' are defined to be 2.5pt from AB. A brace is drawn between A' and B'. In this way, the label for the length of AB is put in the center of the brace by default.
\coordinate (A') at ($(A)!2.5pt!-90:(B)$);
\coordinate (B') at ($(B)!2.5pt!90:(A)$);
\draw[decorate,decoration={brace,amplitude=5pt}] (B') -- node[fill=white, inner sep=1pt]{$\scriptstyle{22}$} (A');

%These commands draw the altitude of the triangle from C. The foot of the altitude is
%labeled P. The length of the altitude is labeled h.
\coordinate (P) at ($(A)!(C)!(B)$);
\draw[dashed] (C) -- (P);
\coordinate (PC_midpoint) at ($(P)!0.5!(C)$);
\node (PC_midpoint_label) at ($(PC_midpoint) + (90:7.5pt)$) {$\scriptstyle{h}$};

%The following commands make the right-angle mark.
\coordinate (U) at ($(P)!4mm!-45:(A)$);
\draw (U) -- ($(P)!(U)!(A)$);
\draw (U) -- ($(P)!(U)!(C)$);

\end{tikzpicture}

\end{document}

答案1

由于raise移动brace装饰,您需要进行一些手动微调,例如:

node[fill=white, inner sep=1pt,above left=8pt and 16pt] {$\scriptstyle 22$} (A);

完整示例:

\documentclass{amsart}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\begin{document}

\begin{tikzpicture}
%A is the vertex of an angle of 55 degrees; the sides of this angle are AB
%and AC. $AB = 22$ and $AC = 13$.
\coordinate (A) at (0,0);
\node (vertex_A) at ($(A) + (82.5:7.5pt)$){$A$};
\coordinate (B) at (235:5.5);
\node (vertex_B) at ($(B) + (225:7.5pt)$){$B$};
\coordinate (C) at (290:3.25);
\node (vertex_C) at ($(C) + (-45:7.5pt)$){$C$};
\draw[name path=AB] (A) -- (B);
\draw[name path=AC] (A) -- (C);
\draw[name path=BC] (B) -- (C);

\path pic[draw, angle radius=5mm,"$\scriptstyle{55}$",angle eccentricity=1.5] {angle = B--A--C};

%These commands label the lengths of AB and of AC.
\coordinate (AB_midpoint) at ($(A)!0.5!(B)$);
\draw[decorate,decoration={brace,raise=12pt,amplitude=5pt}] 
  (B) -- node[fill=white, inner sep=1pt,above left=8pt and 16pt]{$\scriptstyle 22$} (A);
\coordinate (AC_midpoint) at ($(A)!0.5!(C)$);
\node (AC_midpoint_label) at ($(AC_midpoint) + (20:7.5pt)$) {$\scriptstyle{13}$};


%These commands draw the altitude of the triangle from C. The foot of the altitude is
%labeled P. The length of the altitude is labeled h.
\coordinate (P) at ($(A)!(C)!(B)$);
\draw[dashed] (C) -- (P);
\coordinate (PC_midpoint) at ($(P)!0.5!(C)$);
\node (PC_midpoint_label) at ($(PC_midpoint) + (90:7.5pt)$) {$\scriptstyle{h}$};

%The following commands make the right-angle mark.
\coordinate (U) at ($(P)!4mm!-45:(A)$);
\draw (U) -- ($(P)!(U)!(A)$);
\draw (U) -- ($(P)!(U)!(C)$);

\end{tikzpicture}

\end{document}

结果:

在此处输入图片描述

更新

编辑完题目后,raise不再使用,而是使用一些辅助坐标来绘制括号。但是,仍然需要一些手动干预:

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}



\begin{document}

\begin{tikzpicture}

%A is the vertex of an angle of 55 degrees; the sides of this angle are AB
%and AC. $AB = 22$ and $AC = 13$.
\coordinate (A) at (0,0);
\node (vertex_A) at ($(A) + (82.5:7.5pt)$){$A$};
\coordinate (B) at (235:5.5);
\node (vertex_B) at ($(B) + (225:7.5pt)$){$B$};
\coordinate (C) at (290:3.25);
\node (vertex_C) at ($(C) + (-45:7.5pt)$){$C$};
\draw[name path=AB] (A) -- (B);
\draw[name path=AC] (A) -- (C);
\draw[name path=BC] (B) -- (C);

\path pic[draw, angle radius=5mm,"$\scriptstyle{55}$",angle eccentricity=1.5] {angle = B--A--C};

%These commands label the length of AC.
\coordinate (AC_midpoint) at ($(A)!0.5!(C)$);
\node (AC_midpoint_label) at ($(AC_midpoint) + (20:7.5pt)$) {$\scriptstyle{13}$};


%These commands put a brace above line segment AB and label the length `22`.  First, coordinates A' and B' are defined to be 2.5pt from AB. A brace is drawn between A' and B'. In this way, the label for the length of AB is put in the center of the brace by default.
\coordinate (A') at ($(A)!2.5pt!-90:(B)$);
\coordinate (B') at ($(B)!2.5pt!90:(A)$);
\draw[decorate,decoration={brace,amplitude=5pt}] 
  (B') -- node[above left=0pt and 3pt]{$\scriptstyle 22$} (A');

%These commands draw the altitude of the triangle from C. The foot of the altitude is
%labeled P. The length of the altitude is labeled h.
\coordinate (P) at ($(A)!(C)!(B)$);
\draw[dashed] (C) -- (P);
\coordinate (PC_midpoint) at ($(P)!0.5!(C)$);
\node (PC_midpoint_label) at ($(PC_midpoint) + (90:7.5pt)$) {$\scriptstyle{h}$};

%The following commands make the right-angle mark.
\coordinate (U) at ($(P)!4mm!-45:(A)$);
\draw (U) -- ($(P)!(U)!(A)$);
\draw (U) -- ($(P)!(U)!(C)$);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容