我设法将斜边文本与三角形的斜边对齐,但我觉得~~~~~~
在这一行中使用了很多东西,效率很低node[above] {$\sqrt{1+x^2}$~~~~~~~} (B) --
。
有没有更好的方法来获得与我现在相同的对齐,而无需过度使用~
?
\documentclass[hidelinks,14pt, letterpaper]{extarticle}
\usepackage{amsmath, amssymb, tikz}
\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw
(A) --
node[above] {$\sqrt{1+x^2}$~~~~~~~} (B) --
node[right] {?} (C) --
node[below] {?}
(A);
\draw
(1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\end{document}
答案1
像这样吗?我使用node[midway,above left=0pt,inner sep=0.5pt] {$\sqrt{1+x^2}$}
,其中inner sep=0.5pt
控制距离。
\documentclass[hidelinks,14pt, letterpaper]{extarticle}
\usepackage{amsmath, amssymb, tikz}
\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\draw
(A) --
node[midway,above left=0pt,inner sep=0.5pt] {$\sqrt{1+x^2}$} (B) --
node[right] {?} (C) --
node[below] {?}
(A);
\draw
(1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\end{document}
附录:只是为了好玩:使用 Ti 编写更简单、更短的代码钾是……
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1.25]
\draw (-1.5,-1) coordinate [label=left:$A$] (A) --
node[midway,above,sloped] {$\sqrt{1+x^2}$}
(1.5,1) coordinate [label=above:$B$] (B) --
node[right] {?}
(1.5,-1)coordinate [label=below right:$C$] (C) --
node[below] {?} cycle;
\draw ([xshift=-0.25cm]C) |- ([yshift=0.25cm]C);
\end{tikzpicture}
\end{document}
答案2
只是为了好玩:用pstricks
一个非常短的代码来得到这个数字:
\documentclass{article}
\usepackage{pst-eucl}%,
\usepackage{auto-pst-pdf}
\begin{document}
\begin{postscript}
\psset{unit=2, linejoin=1, PointSymbol=none,}
\pstTriangle(-1.5,-1){A}(1.5,1){B}(1.5,-1){C}
\ncline[linestyle=none]{A}{B}\naput*[nrot=:U]{$ \sqrt{1 + x^2}$}
\psset{PointName=none}
\pstMiddleAB{A}{C}{I}\uput[d](I){?}
\pstMiddleAB{B}{C}{J}\uput[r](J){?}
\end{postscript}
\end{document}