Graphics, Figures & Tablesusing edge in tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
kenth
Posts: 9
Joined: Sat Jul 09, 2022 8:28 pm

using edge in tikz

Post by kenth »

I have a rectangle ABCD and I want to put node info on the its sides and diagonals.

If i do this as in the attached .tex file (see also below), it works for AB, but not for AC, the path starts at B and not A.
It seems that for AC it still uses the last position from AB. How do I reset this position to (A)?

\def\mymacro[#1,#2]{\tikz [every edge quotes/.style={fill=white}] \draw[gray] (#1) edge ["mid"',<->] (#2)};

\mymacro[A,B]; %this gives the edge on the side AB of the rectangle as expected .
\mymacro[A,C]; %however, here the path (as said above) is starting at B, not A.

See the attached files attachment.tex and attachment.pdf -

How can I fix this? Anybody?
Attachments
attachment.pdf
(19.79 KiB) Downloaded 185 times
attachment.tex
(1.93 KiB) Downloaded 110 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz

Post by Stefan Kottwitz »

Hi Kenth,

welcome to the forum!

Just don't use \tikz in the macro, because that starts another TikZ picture.

Change

Code: Select all

\def\mymacro[#1,#2]{\tikz [every edge quotes/.style={fill=white}]
  \draw[gray] (#1) edge ["mid"',<->] (#2)};
to

Code: Select all

\def\mymacro[#1,#2]{\draw[gray] (#1) edge ["mid"',<->] (#2)};
and move every edge quotes/.style={fill=white} for example to the tikzpicture options.

Stefan
LaTeX.org admin
kenth
Posts: 9
Joined: Sat Jul 09, 2022 8:28 pm

using edge in tikz

Post by kenth »

Thanks, it works.
One follow-up question:
If I want mid in bold and mid sloped along the line (diagonal), what do I need to do?
Kent
kenth
Posts: 9
Joined: Sat Jul 09, 2022 8:28 pm

using edge in tikz

Post by kenth »

I solved the slope issue. (Easy in fact, by adding sloped below.)

I would really like the label (here "mid") to be bold and given by as a parameter of the macro such as
\def\mymacro[#1,#2,#3,#4]{\draw[#4] (#1) edge [#3,sloped,<->] (#2)};
This seems not to work.
Anybody?
Kent
Post Reply