LaTeX forum ⇒ Graphics, Figures & Tablesusing edge in tikz II

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 II

Postby kenth » Fri Jul 15, 2022 10:14 am

I use edge to place lables along straight line.
I should want to the lines and the node with different colours, see the attached files.
Anybody?
Attachments
latexforumposting.pdf
(17.43 KiB) Downloaded 31 times
latexforumposting.tex
(1.95 KiB) Downloaded 31 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 II

Postby Stefan Kottwitz » Sat Jul 16, 2022 3:21 pm

You can have style options for the quoted nodes, such as:

\draw [red,thick] (A) to ["txt" '{fill=blue,text=yellow}] (B);


While the color (red) is applied to the whole path, this style options override it for the text, and if you use edge instead of to, you can even override the line color, such as:

\draw [red,thick] (A) edge ["txt" '{fill=blue,text=yellow}, green] (B);


because edge produces its own path.

Stefan
LaTeX.org admin

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

using edge in tikz II

Postby kenth » Sun Jul 17, 2022 9:09 am

Great! Thanks.
One last question if I may: How to turn the label as bold?
Kent

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

using edge in tikz II

Postby Stefan Kottwitz » Sun Jul 17, 2022 3:25 pm

Hi Kent,

this way: to ["text" '{font=\bfseries}]

Stefan
LaTeX.org admin

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

using edge in tikz II

Postby kenth » Sun Jul 17, 2022 4:52 pm

Again, thank you very much! :D
Kent

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

using edge in tikz II

Postby kenth » Sun Jul 17, 2022 5:45 pm

Can we avoid the "-s around the label?

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

using edge in tikz II

Postby Stefan Kottwitz » Sun Jul 17, 2022 6:30 pm

Hi Kent,

not sure what you mean - in the output, or in the code? In the code "..." is a shortcut for a node syntax, so you can write

\draw (A) to ["text"] (C);


instead of

\draw (A) to node [sloped] {text} (C);


Stefan
LaTeX.org admin

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

using edge in tikz II

Postby kenth » Mon Jul 18, 2022 10:07 am

To be precise, I want the macro
\def\mgElabel[#1,#2,#3,#4]{
\draw [#4] (#1) edge [#3 {fill=gray!20,text=black,font=\bfseries}] (#2);
}
to work with the label (argument #3) given without sourounding double apostrophes, i.e. text
instead of "text".

In addition, I have the following defined in my .tex file
\usetikzlibrary{quotes}
...
\begin{tikzpicture}[scale=\scalefactor,every edge quotes/.style={fill=gray!20,sloped}]
. . .
\mgElabel[A,C,"text",red];
. . .

\mgElabel[A,C,"text",red] works fine, but, \mgElabel[A,C,text,red] does not.

Kent

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

using edge in tikz II

Postby Stefan Kottwitz » Tue Jul 19, 2022 8:08 am

Hi Kent,

the quotes are needed, but you could put them into the macro definition:

\def\mgElabel[#1,#2,#3,#4]{
\draw [#4] (#1) edge ["#3" {fill=gray!20,text=black,font=\bfseries}] (#2);
}

Stefan
LaTeX.org admin

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

using edge in tikz II

Postby kenth » Tue Jul 19, 2022 10:28 am

Stefan, thanks for your quick and kind responses!
For me, edge has been new.
Up to now I have only used node.
Kent


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 11 guests