Graphics, Figures & TablesUsage of TikZ with Lyx

Information and discussion about graphics, figures & tables in LaTeX documents.
kocan
Posts: 7
Joined: Fri Mar 14, 2025 9:54 pm

Usage of TikZ with Lyx

Post by kocan »

Hello,

I would like some help regarding the usage of tikz with lyx. When I have simple tikz code, it works fine. If the tikz code becomes a little complex suc as including tikzset, I do get error. What is the cause of this error? I put the required packages to the preamble.

Thank you in advance, Kocan

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

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

Hello Kocan,

welcome to the forum!
kocan wrote: Fri Mar 14, 2025 10:09 pm I do get an error.
What error message do you get?
kocan wrote: Fri Mar 14, 2025 10:09 pm What is the cause of this error?
How is the code?

Best regards,

Stefan
LaTeX.org admin
kocan
Posts: 7
Joined: Fri Mar 14, 2025 9:54 pm

Re: Usage of TikZ with Lyx

Post by kocan »

Hello Stefan,
Thank you accepting me to the forum.

This code successfully:
\begin{tikzpicture}
% Define the nodes (vertices)
\node[circle, draw=blue, fill=blue!20, minimum size=15mm] (A) at (0, 0) {1};
\node[circle, draw=blue, fill=blue!20, minimum size=15mm] (B) at (4, 0) {2};
\node[circle, draw=blue, fill=blue!20, minimum size=15mm] (C) at (2, 3) {3};
\node[circle, draw=blue, fill=blue!20, minimum size=15mm] (D) at (5, 4) {4};
\node[circle, draw=blue, fill=blue!20, minimum size=15mm] (E) at (1, 4) {5};

% Draw the edges with weights
\draw[thick] (A) -- (B) node[midway, below] {2};
\draw[thick] (A) -- (C) node[midway, left] {4};
\draw[thick] (B) -- (C) node[midway, right] {6};
\draw[thick] (C) -- (D) node[midway, above right] {3};
\draw[thick] (C) -- (E) node[midway, left] {5};
\draw[thick] (D) -- (E) node[midway, below right] {1};

\end{tikzpicture}


Here is the failing code :
error = "TeX capacity exceeded, sorry [input stack size=10000]."
If I move tikzset to preamble, it works for this example.
I am also getting the same error I wanted to put some vertices into a cloud.

\begin{tikzpicture}
\tikzset{
% Style for nodes (vertices)
mynode/.style={
circle,
draw=blue,
fill=blue!20,
minimum size=15mm,
font=\large
},
% Style for edges
myedge/.style={
thick,
draw=black
},
% Style for edge weights
myweight/.style={
midway,
font=\small,
sloped
}
}
% Define the nodes (vertices)
\node[mynode] (A) at (0, 0) {1};
\node[mynode] (B) at (4, 0) {2};
\node[mynode] (C) at (2, 3) {3};
\node[mynode] (D) at (5, 4) {4};
\node[mynode] (E) at (1, 4) {5};

% Draw the edges with weights
\draw[myedge] (A) -- (B) node[myweight] {2};
\draw[myedge] (A) -- (C) node[myweight] {4};
\draw[myedge] (B) -- (C) node[myweight] {6};
\draw[myedge] (C) -- (D) node[myweight] {3};
\draw[myedge] (C) -- (E) node[myweight] {5};
\draw[myedge] (D) -- (E) node[myweight] {1};
\end{tikzpicture}

Thank you for your help. , Fatih
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

Hi Fatih,

when you copy code into ERTs, line breaks are not preserved, so the code after the % comment is not seen as LyX considers it commented out. (similar seen here)

Try without the comments like "% Style for nodes (vertices)" etc., at least for testing.

Stefan
LaTeX.org admin
kocan
Posts: 7
Joined: Fri Mar 14, 2025 9:54 pm

Re: Usage of TikZ with Lyx

Post by kocan »

Hi Stefan,

"Illegal parameter number in definition of \pgfkeyscurrentkey." this is the error for the following tikz code:

\begin{tikzpicture}

\tikzset{
vertex/.style={circle, draw=black, fill=blue!30, minimum size=1.2cm, font=\bfseries},
edge/.style={thick},
weight/.style={font=\small, fill=white, inner sep=1pt}
}


\node (A) [vertex, fill=green!50] at (0,2) {A};
\node (B) [vertex, fill=green!50] at (4,2) {B};
\node (C) [vertex, fill=green!50] at (0,0) {C};
\node (D) [vertex, fill=green!50] at (4,0) {D};
\node (E) [vertex, fill=green!50] at (6,1) {E};


\draw[edge] (A) -- node[weight] {4} (B);
\draw[edge] (A) -- node[weight] {1} (C);
\draw[edge] (B) -- node[weight] {2} (D);
\draw[edge] (C) -- node[weight] {4} (D);
\draw[edge] (B) -- node[weight] {5} (E);
\draw[edge] (D) -- node[weight] {3} (E);


\node at ($(A) + (0,0.8)$) {\textbf{0}};
\node at ($(B) + (0,0.8)$) {\textbf{4}};
\node at ($(C) + (0,-0.8)$) {\textbf{1}};
\node at ($(D) + (0,0.8)$) {\textbf{5}};
\node at ($(E) + (0,-0.8)$) {\textbf{8}};
\end{tikzpicture}

Best regards, Fatih
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

Instead of \tikzset, you can use it in square brackets as options:

Code: Select all

Code, edit and compile here:
\begin{tikzpicture}[
vertex/.style = {circle, draw=black, fill=blue!30,
minimum size=1.2cm, font=\bfseries},
edge/.style = {thick},
weight/.style = {font=\small, fill=white, inner sep=1pt}
]
...
\end{tikzpicture}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Does this help?

Stefan
LaTeX.org admin
kocan
Posts: 7
Joined: Fri Mar 14, 2025 9:54 pm

Re: Usage of TikZ with Lyx

Post by kocan »

Hi Stefan,

I received the same error:
"Illegal parameter number in definition of \pgfkeyscurrentkey."

Thank you in advance,
Fatih
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

Can you perhaps post the .log file, so we see the full context of that error and where it occurs exactly?

Stefan
LaTeX.org admin
kocan
Posts: 7
Joined: Fri Mar 14, 2025 9:54 pm

Re: Usage of TikZ with Lyx

Post by kocan »

Sorry. it took awhile to find the log file.

Code: Select all

This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2023.2.2) 15 MAR 2025 20:30
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**0-1_Knapsack.tex
(./0-1_Knapsack.tex
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-01-24>
(c:/texlive/2022/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(c:/texlive/2022/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2022/07/02 v1.4n Standard LaTeX file (size option)
)
\c@part=\count185
\c@section=\count186
\c@subsection=\count187
\c@subsubsection=\count188
\c@paragraph=\count189
\c@subparagraph=\count190
\c@figure=\count191
\c@table=\count192
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen140
) (c:/texlive/2022/texmf-dist/tex/latex/base/fontenc.sty
Package: fontenc 2021/04/29 v2.0v Standard LaTeX package
) (c:/texlive/2022/texmf-dist/tex/latex/base/inputenc.sty
Package: inputenc 2021/02/14 v1.3d Input encoding file
\inpenc@prehook=\toks16
\inpenc@posthook=\toks17
) (c:/texlive/2022/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2022/04/08 v2.17n AMS math features
\@mathmargin=\skip50
For additional information on amsmath, use the `?' option.
(c:/texlive/2022/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2021/08/26 v2.01 AMS text
(c:/texlive/2022/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0 generic functions
\@emptytoks=\toks18
\ex@=\dimen141
)) (c:/texlive/2022/texmf-dist/tex/latex/amsmath/amsbsy.sty
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

The error is in 0-1_Knapsack.tex, can you post the file here as attachment? Or if it's short, directly in the post.

Stefan
LaTeX.org admin
Post Reply