## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ using edge in tikz

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

### using edge in tikz

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
attachment.tex

LaTeXguide.org • LaTeX-Cookbook.net

Stefan Kottwitz
Posts: 9878
Joined: Mon Mar 10, 2008 9:44 pm

### using edge in tikz

Hi Kenth,

welcome to the forum!

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

Change

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

to

\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

kenth
Posts: 9
Joined: Sat Jul 09, 2022 8:28 pm

### using edge in tikz

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

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