3

I would like to make the vertical bars in the \draw[|<->|] command a bit longer. Can I do that with little editing to the following code?

\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
  • something like [->{|[width=2cm]}|] might work
    – Symbol 1
    Jul 26, 2021 at 22:28

1 Answer 1

7

I rewrote your code ...

  • for drawing rectangles is used nodes with rectangle shape
  • at determining their size I had problem: it was not entirely clear (to me), why you use so complicated calculation of their width and height. I replace them with simple integers.
  • for arrows for measuring their lenght and height is used arrows.meta library which enable simple adjustment of width of bars:
\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}

enter image description here

1
  • Including the options "shorten >=-0.5\pgflinewidth, shorten <=-0.5\pgflinewidth" is a fine choice.
    – user74973
    Aug 8, 2021 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .