这可能是一个非常简单的问题。我该如何将黄色显示的标签添加到下面的方块中?
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) rectangle (4,4);
%
\node [above] at (0,4) {$A$};
\node [below] at (0,0) {$B$};
\node [below] at (4,0) {$C$};
\node [above] at (4,4) {$D$};
\node [above] at (2,2.1) {$O$};
%
\draw[thick] (0,0) -- (4,4);
\draw[thick] (0,4) -- (4,0);
%
%\draw[thick,dashed](0,4) -- node[fill=white]{$10\text{ m}$}(4,0);
\end{tikzpicture}
\end{document}
谢谢!
答案1
像这样:
对于上图,您需要在图片代码中添加以下代码行:
\draw[thick,yellow] (0,4) to [bend right] node[fill=white,text=black] {\SI{10}{cm}} (4,0);
完成 MWE:
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{siunitx} % <--- new package
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) rectangle (4,4);
%
\node [above] at (0,4) {$A$};
\node [below] at (0,0) {$B$};
\node [below] at (4,0) {$C$};
\node [above] at (4,4) {$D$};
\node [above] at (2,2.1) {$O$};
%
\draw[thick] (0,0) -- (4,4)
(0,4) -- (4,0);
\draw[thick,yellow] (0,4) to [bend right] node[fill=white,text=black] {\SI{10}{cm}} (4,0); % <---
\end{tikzpicture}
\end{document}
答案2
我会命名坐标,并且默认避免覆盖现有线条。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) coordinate[label=below:$B$](B) rectangle (4,4)
coordinate[label=above:$D$](D)
(B|-D)coordinate[label=above:$A$](A) (B-|D)coordinate[label=below:$C$](C);
%
\node [above] at (2,2.1) {$O$};
%
\draw[thick] (A) -- (C) (B) -- (D);
%
%\draw[thick,dashed](0,4) -- node[fill=white]{$10\text{ m}$}(4,0);
\path (A) to[bend right] node(10cm){\SI{10}{\centi\meter}}(C)
(A) edge[bend right=10] (10cm) (10cm) edge[bend right=10] (C);
\end{tikzpicture}
\end{document}
或者
\documentclass[tikz,border=3mm]{standalone}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) coordinate[label=below:$B$](B) rectangle (4,4)
coordinate[label=above:$D$](D)
(B|-D)coordinate[label=above:$A$](A) (B-|D)coordinate[label=below:$C$](C);
%
\node [above] at (2,2.1) {$O$};
%
\draw[thick] (A) -- (C) (B) -- (D);
%
%\draw[thick,dashed](0,4) -- node[fill=white]{$10\text{ m}$}(4,0);
\path (A) to[bend right] node[fill=white,fill opacity=0.6](10cm){\SI{10}{\centi\meter}}(C)
(A) edge[bend right=10] (10cm) (10cm) edge[bend right=10] (C);
\end{tikzpicture}
\end{document}