问题:无法在 LyX 中显示 TikZ 代码下方的文本”

问题:无法在 LyX 中显示 TikZ 代码下方的文本”

我目前在 LyX 中面临一个挑战,在输入几行文本后,我将 TikZ 代码插入 TeX 框内或直接插入到 apex 序言中。但是,我发现 TikZ 代码后面的文本不可见。如果将代码放在序言中,我在文档中编写的文本均不可见。我正在寻求帮助来解决这个问题,并了解如何确保在 LyX 中正确显示插入的 TikZ 代码下方的文本。任何指导或解决方案都将不胜感激。

LyX 文件:

 #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 序言:

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

答案1

不作为解决方案,仅作为参考。

在其中一个 LyX 视图中查看完整的源文档应该与此类似:

  • 序言中有很多不同之处,但至少与下面提到的软件包不同
  • 文件主体原样

顺便说一句,我没有花精力重构你的Tikz代码,只是想提供参考。

% ~~~ 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}

结果

答案2

好的,之后关于 Latex 代码的参考,这里有一个解决方案,假设您在使用 LyX 时可能遇到了麻烦。

可能有效的程序是这样的,其中我强调了menu- and dialogbox actions

  • 从模板创建一个新的 Lyx 文件
  • 如果需要,可以通过以下方式更改 DocumentclassDocument/Settings
  • 输入文本,正如你所做的那样
  • insert TEX,然后进入例如 tikzpicture 环境
  • 通过Document/Settings, LaTeX preamble输入 LyX 中其他地方未列出的包以避免编译错误(缺少包)Apply,,Close
  • 之后继续写
  • export需要时转换为 .pdf

此屏幕截图比较了 LyX 主窗口、LaTeX 预览和所描述的各种菜单操作的结果:

微软视窗系统

这是导出的 .pdf 的屏幕截图:

pdf

请注意,LaTeX 预览大致如下我的参考

  • LyX 更改了序言,但您也可以在此处查看相关部分
  • 之后的内容部分\begin{document}几乎与描述的一样,只是偶尔有一点 LyX 的干预

顺便说一下,这是上面截图中的 Lyx 文件:

#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

相关内容