LaTeX forum ⇒ Graphics, Figures & Tablesusing 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

Postby kenth » Sun Jul 10, 2022 11:03 am

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 48 times
attachment.tex
(1.93 KiB) Downloaded 19 times

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Stefan Kottwitz
Site Admin
Posts: 9882
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz

Postby Stefan Kottwitz » Sun Jul 10, 2022 7:50 pm

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
LaTeX.org admin

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

using edge in tikz

Postby kenth » Mon Jul 11, 2022 12:43 pm

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

Postby kenth » Tue Jul 12, 2022 10:53 am

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


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 9 guests