我想让\draw[|<->|]
命令中的竖线更长一些。我可以通过对以下代码进行少量编辑来实现这一点吗?
\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{array, boldline, makecell}
\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
%A rectangle of length b + c and width a is drawn, and below it, two rectangles of lengths b and c and width a are drawn.
%(The figure is magnified by a scale of 2/3.)
\path (0,0) coordinate (A) ({(2/3)*15},0) coordinate (B) ({(2/3)*15},{(2/3)*3}) coordinate (C) (0,{(2/3)*3}) coordinate (D);
\path[fill=Dandelion] (A) -- ($(A)!2/5!(B)$) -- ($(C)!3/5!(D)$) -- (D) -- cycle;
\path[fill=Turquoise] ($(A)!2/5!(B)$) -- (B) -- (C) -- ($(C)!3/5!(D)$) -- cycle;
\draw[dashed] ($(A)!2/5!(B)$) -- ($(D)!2/5!(C)$);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\draw[|<->|] ($(A)!4mm!90:(D)$)--node[fill=white,sloped] {$a$} ($(D)!4mm!-90:(A)$);
\draw[|<->|] ($(D)!4mm!90:($(D)!2/5!(C)$)$)--node[fill=white,sloped] {$b$} ($($(D)!2/5!(C)$)!4mm!-90:(D)$);
\draw[|<->|] ($($(D)!2/5!(C)$)!4mm!90:(C)$)--node[fill=white,sloped] {$c$} ($(C)!4mm!-90:($(D)!2/5!(C)$)$);
\draw[|<->|] ($(A)!4mm!-90:(B)$)--node[fill=white,sloped] {$b+c$} ($(B)!4mm!90:(A)$);
\node at ($($(A)!1/5!(B)$) +($(A)!1/2!(D)$)$){$ab$};
\node at ($($(A)!7/10!(B)$) +($(A)!1/2!(D)$)$){$ac$};
\end{tikzpicture}
\end{document}
答案1
我重写了你的代码......
- 用于绘制矩形的是具有
rectangle
形状的节点 - 在确定它们的大小时我遇到了问题:我不太清楚为什么使用如此复杂的宽度和高度计算。我用简单的整数代替它们。
- 对于箭头的长度和高度测量,使用
arrows.meta
库可以简单地调整条的宽度:
\documentclass[border=3.141592]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc,
fit,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 0pt,
LAA/.style = {{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}, % <---
shorten >=-0.5\pgflinewidth, shorten <=-0.5\pgflinewidth},
box/.style args = {#1:#2:#3}{minimum width=#1, minimum height=#2, fill=#3,
inner sep=0pt, outer sep=0pt},
every edge quotes/.style = {font=\small, fill=white, inner sep=2pt, anchor=center}
]
% boxes
\node (a) [box=3cm:2cm:Dandelion] {$ab$};
\node (b) [box=4cm:2cm:Turquoise,right=of a] {$ac$};
\draw[densely dashed] (a.north east) -- (a.south east);
\node (c) [draw, inner sep=0pt, fit=(a) (b)] {};
% coordinates for measures
\coordinate[above=4mm of a.north west] (m1);
\coordinate[left =4mm of a.north west] (m2);
\coordinate[below=4mm of a.south west] (m3);
% measures
\draw[LAA] (m1) to ["$b$"] (m1 -| a.east);
\draw[LAA] (m1 -| a.east) to ["$c$"] (m1 -| b.east);
%
\draw[LAA] (m2) to ["$a$"] (m2 |- a.south);
%
\draw[LAA] (m3) to ["$b+c$"] (m3 -| b.east);
\end{tikzpicture}
\end{document}