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

Re: Usage of TikZ with Lyx

Post by kocan »

Hi Stefan,

when I remove tikzpicture, I am successfully able to see the pdf document.

Attached the .tex file.
Attachments
0-1 Knapsack.tex
(6.22 KiB) Downloaded 249 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
Stefan Kottwitz
Site Admin
Posts: 10311
Joined: Mon Mar 10, 2008 9:44 pm

Re: Usage of TikZ with Lyx

Post by Stefan Kottwitz »

In the code, I can see that you use the turkish language, with babel. So, load the babel TikZ library in your preamble:

Code: Select all

\usetikzlibrary{babel}
That's because turkish babel shortcut codes cause an issue with TikZ codes. \shorthandoff{=} after \begin{document} would also work, for the same reason, but then you could not use the "=" shortcut.

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

Re: Usage of TikZ with Lyx

Post by kocan »

Thank you Stefan,
I got this worked.


\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}
]


\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}
Post Reply