Graphics, Figures & Tablesusing edge in tikz II

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 II

Post by kenth »

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 162 times
latexforumposting.tex
(1.95 KiB) Downloaded 143 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: 10323
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz II

Post by Stefan Kottwitz »

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

Code: Select all

\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:

Code: Select all

\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

Post by kenth »

Great! Thanks.
One last question if I may: How to turn the label as bold?
Kent
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz II

Post by Stefan Kottwitz »

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

Post by kenth »

Again, thank you very much! :D
Kent
kenth
Posts: 9
Joined: Sat Jul 09, 2022 8:28 pm

using edge in tikz II

Post by kenth »

Can we avoid the "-s around the label?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz II

Post by Stefan Kottwitz »

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

Code: Select all

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

Code: Select all

\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

Post by kenth »

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: 10323
Joined: Mon Mar 10, 2008 9:44 pm

using edge in tikz II

Post by Stefan Kottwitz »

Hi Kent,

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

Code: Select all

\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

Post by kenth »

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