0

I am currently facing a challenge in LyX where, after typing several lines of text, I insert TikZ code either inside a TeX box or directly into the apex preamble. However, I have observed that the text following the TikZ code is not visible. In the case of placing the code in the preamble, none of the text I have written in the document is visible. I am seeking assistance in resolving this issue and understanding how to ensure the proper display of text below inserted TikZ code in LyX. Any guidance or solutions would be greatly appreciated.

LyX file:

 #LyX 2.3 created this file. For more info see 
http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
...
\end_header
\begin_body
\begin_layout Standard
Text here.
1
Algorithms - question 1
1
.

~~~Trying to show the figure here ~~~

~~~ Text of the solution that isn't shown in rendered pdf~~~

\end_layout
\end_body
\end_document

LaTeX preamble:

\usepackage{autobreak}
\usepackage{fontspec}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{autobreak}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{polyglossia}
\usepackage{tikz}
\setmainlanguage{hebrew}
\setotherlanguage{english}

\spaceskip=1\fontdimen2\font plus 1\fontdimen3\font minus 1.5\fontdimen4\font
\everymath{\, }

\usepackage{xcolor}
\definecolor{blue}{RGB}{14,107,217}
\definecolor{green}{RGB}{0,158,40}
\definecolor{red}{RGB}{235,16,16}
\definecolor{brown}{RGB}{164,66,0}
\definecolor{orange}{RGB}{231,135,26}
\definecolor{purple}{RGB}{94,53,177}

\usepackage{amssymb}
\renewcommand{\qedsymbol}{$\blacksquare$}

\pagestyle{empty}
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=2.5cm,
  thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries, minimum size=1cm},
  align=center]

\node[main node] (s) {$s$};
\node[main node] (v1) [below right=0.8cm and 1.8cm of s] {$v_1$};
\node[main node] (v2) [above right=0.8cm and 1.8cm of s] {$v_2$};
\node[main node] (vn-3) [right=1.2cm of v1] {$v_{n-3}$};
\node[main node] (vn-2) [right=1.2cm of v2] {$v_{n-2}$};
\node[main node] (t) [below right=0.8cm and 1.8cm of vn-2] {$t$};

\draw [->] (s) -- (v1);
\draw [->] (s) -- (v2);
\draw [->] (vn-3) -- (t);
\draw [->] (vn-2) -- (t);

\draw [dashed] [->,blue] (v1) -- (vn-2);
\draw [dashed] [->,blue] (v2) -- (vn-3);
\draw [dashed, ->,  bend right] (v1.north) to (v2.south);
\draw [dashed, ->,  bend] (v2.south) to (v1.north);
\draw [dashed, ->,  bend right] (vn-3.north) to (vn-2.south);
\draw [dashed, ->,  bend] (vn-2.south) to (vn-3.north);

% Add dashed lines to represent the cutted paths
\draw [dashed] (s) -- (v1);
\draw [dashed] (s) -- (v2);
\draw [dashed] (v1) -- (vn-3);
\draw [dashed] (v2) -- (vn-2);
\draw [dashed] (vn-3) -- (t);
\draw [dashed] (vn-2) -- (t);

\end{tikzpicture}
\end{document}
6
  • 1
    Welcome. // Please try to add code to your question, which compiles with LyX AND shows your problem. At the moment you're relying on our telepathic skill ... ;-)
    – MS-SPO
    Commented Jan 20 at 10:40
  • 1
    If you don't know, how to make your problem reproducible, please see: LyX user questions on TeX stackexchange.
    – cabohah
    Commented Jan 20 at 11:03
  • 1
    @MS-SPO I fixed, hope it provide more details
    – Evya1
    Commented Jan 20 at 11:37
  • @BEvya, thank you. Can‘t you boil it down much more? Almost nobody here will start debugging, while the problem should be noticeable with many shorter files, too. Thank you.
    – MS-SPO
    Commented Jan 20 at 11:43
  • 1
    @BEvya, I almost unfamiliar with LyX, but what you post looks quite strange. Starting with preamble and file ... doesn't match with my LyX 2.3.* version. If you'd copy that code(s) as a .tex file and compile it: 1) it's strange, that \usepackage is before the documentclass, 2) you include the same \documentclass etc. 4 times or more. How can you expect a valid compile from that? // Looks to me like your error is an artifact from this kind of mis-use. // Suggestion: Start with a fresh file, preferably in a Latex environment, as LyX "creatively" changes Latex code ...
    – MS-SPO
    Commented Jan 20 at 13:13

2 Answers 2

0

Not a solution, but a reference.

Watching the complete source document in one of the LyX-views should be similar to this:

  • lot's of differences in the preamble, but at least with the packages mentioned below
  • the document body as is

BTW, I didn't spend effort to refactor your Tikz code, just want to give a reference.

% ~~~ this is a regular preamble in LaTeX ~~~~~~~~~~~~~~~~~~
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}% <<<
\usepackage{blindtext}  % provides some dummy text

% ~~~ next, this is the document ~~~~~~~~~~~~~~~
\begin{document}

 % ~~~ text before the tikypicture ~
 \blindtext[1]

 \begin{tikzpicture}[->,
    >={Stealth}, % <<<
    auto,node distance=2.5cm,
     thick,
     main node/.style={circle,draw,font=\sffamily\Large\bfseries, minimum size=1cm},
     align=center]

    \node[main node] (s) {$s$};
    \node[main node] (v1) [below right=0.8cm and 1.8cm of s] {$v_1$};
    \node[main node] (v2) [above right=0.8cm and 1.8cm of s] {$v_2$};
    \node[main node] (vn-3) [right=1.2cm of v1] {$v_{n-3}$};
    \node[main node] (vn-2) [right=1.2cm of v2] {$v_{n-2}$};
    \node[main node] (t) [below right=0.8cm and 1.8cm of vn-2] {$t$};
    
    \draw [->] (s) -- (v1);
    \draw [->] (s) -- (v2);
    \draw [->] (vn-3) -- (t);
    \draw [->] (vn-2) -- (t);
    
    \draw [dashed] [->,blue] (v1) -- (vn-2);
    \draw [dashed] [->,blue] (v2) -- (vn-3);
    \draw [dashed, ->,  bend right] (v1.north) to (v2.south);
    \draw [dashed, ->] (v2.south) to (v1.north);% <<< removed bend
    \draw [dashed, ->,  bend right] (vn-3.north) to (vn-2.south);
    \draw [dashed, ->] (vn-2.south) to (vn-3.north);% <<< removed bend
    
    % Add dashed lines to represent the cutted paths
    \draw [dashed] (s) -- (v1);
    \draw [dashed] (s) -- (v2);
    \draw [dashed] (v1) -- (vn-3);
    \draw [dashed] (v2) -- (vn-2);
    \draw [dashed] (vn-3) -- (t);
    \draw [dashed] (vn-2) -- (t);
 \end{tikzpicture}
 
 % ~~~ text after the tikypicture ~
 \blindtext[2]
 
 
\end{document}

result

0

Ok, after my reference about Latex code, here's a solution, under the assumption, that you may have had trouble using LyX.

Probably a valid procedure is like this, where I highlighted the menu- and dialogbox actions:

  • create a new Lyx file from Templates
  • change Documentclass, if needed, via Document/Settings
  • enter text, as you certainly did
  • insert TEX, and enter there e.g. a tikzpicture environment
  • via Document/Settings, LaTeX preamble enter packages not listed elsewhere within LyX to avoid a compile error (missing package), Apply, Close
  • continue writing after that
  • export to .pdf whenever needed

This screenshot compares the LyX Main window, the LaTeX preview and the results of the various menu-operations described:

LyXWindows

While here's a screenshot of the exported .pdf:

pdf

Kindly notice that the LaTeX preview more or less follows my reference:

  • LyX changes the preamble, but you can see the relevant parts also here
  • the content part after \begin{document} is almost as described, with a little LyX intervention here and there

BTW, this is the Lyx-file from aboves screenshot:

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass book
\begin_preamble
\usepackage{tikz}
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
This is my first sentence, typed into the main window of LyX.
 Next insert TEX and type:
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
begin{tikzpicture}
\end_layout

\begin_layout Plain Layout

    
\backslash
draw (0,0) -- +(1,1);
\end_layout

\begin_layout Plain Layout


\backslash
end{tikzpicture}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This won't compile as the tikz-package is missing.
 So:
\end_layout

\begin_layout Standard
Document/Settings, enter under LaTeX preamble:
\end_layout

\begin_layout Standard

\backslash
usepackage{tikz}
\end_layout

\begin_layout Standard
Apply & Close
\end_layout

\begin_layout Standard
Export to pdf
\end_layout

\end_body
\end_document

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .