## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ using 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

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

LaTeXguide.org • LaTeX-Cookbook.net

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

### using edge in tikz II

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

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

### using edge in tikz II

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

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

### using edge in tikz II

Hi Kent,

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

Stefan

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

### using edge in tikz II

Again, thank you very much!
Kent

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

### using edge in tikz II

Can we avoid the "-s around the label?

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

### using edge in tikz II

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);

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

Stefan

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

### using edge in tikz II

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

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

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

### using edge in tikz II

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

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

### using edge in tikz II

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