我可以使用 TikZ 在线绘制图形(图论)吗?

我可以使用 TikZ 在线绘制图形(图论)吗?

我有一个问题,我是一名硕士生,我正在用 LaTeX 撰写我的论文(图论)。

谁能帮我找到一个在线网站来绘制图表然后在线插入 LaTeX 中的代码?

答案1

以下是使用 R 中的 igraph 包并使用 knitr 和 pdflatex 将结果嵌入 pdf 文件的示例。根据您的操作系统和设置,实际工作流程细节可能会有所不同。

一般来说,1) 使用嵌入的 R 命令创建 latex 文件。使用扩展名 *.Rnw(区分大小写)保存该文件 2) 现在使用 R 对该 *.Rnw 文件运行 knit 命令。您将不会获得与原始 *.Rnw 文件具有相同基本名称的 *.tex 文件。3) 运行 pdflatex,然后查看 *.pdf 文件。

以下是示例源文件(摘自http://www.r-graph-gallery.com/247-network-chart-layouts/)。

\documentclass[10pt,letterpaper]{article}
\begin{document}
Demo of Graph Theory using R and Tikz
<<>>=
# library
library(igraph)

# Create data
data=matrix(sample(0:1, 400, replace=TRUE, prob=c(0.8,0.2)), nrow=20)
network=graph_from_adjacency_matrix(data , mode='undirected', diag=F )

# When ploting, we can use different layouts:
par(mfrow=c(2,2), mar=c(1,1,1,1))
plot(network, layout=layout.sphere, main="sphere")
plot(network, layout=layout.circle, main="circle")
plot(network, layout=layout.random, main="random")
plot(network, layout=layout.fruchterman.reingold, main="fruchterman.reingold")
@
\end{document}

结果是

在此处输入图片描述

答案2

你可以考虑注册一个免费的萨基马云帐户为您提供计算机代数系统 Sage 的强大功能以及sagetexLaTeX 中的软件包;文档这里。Sage 具有图论知识;例如命名图图形参数, 乃至LaTeX 选项。这意味着您可以使用或使用 Sage 的强大功能来创建图表tikz来处理细节。以下是示例:

\documentclass{article}
\usepackage{sagetex}
\usepackage{tikz,tkz-graph,tkz-berge}
\thispagestyle{empty}
\begin{document}
Here's a graph where you specify the position of the vertices. Note that  the label is placed inside unless specified:\\\\
\begin{center}
\begin{tikzpicture}[scale=1.5]
\renewcommand*{\VertexLineWidth}{1pt}%vertex thickness
\renewcommand*{\EdgeLineWidth}{1pt}% edge thickness
\GraphInit[vstyle=Normal]
\Vertex[Lpos=270,L=$v_1$,x=0,y=0]{R1}
\Vertex[LabelOut,Lpos=270,L=$v_2$,x=0,y=2]{R2}
\Vertex[LabelOut,Lpos=270,L=$v_3$,x=1,y=1]{R3}
\Vertex[LabelOut,Lpos=270,L=$v_4$,x=2,y=1]{R4}
\Vertex[LabelOut,Lpos=270,L=$v_5$,x=3,y=1]{R5}
\Vertex[LabelOut,Lpos=270,L=$v_6$,x=4,y=1]{R6}
\Vertex[LabelOut,Lpos=90,L=$v_7$,x=3,y=2]{R7}
\Vertex[LabelOut,Lpos=90,L=$v_8$,x=4,y=2]{R8}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Edge (R3)(R4)
\Edge (R3)(R1)
\Edge (R2)(R3)
\Edge (R5)(R4)
\Edge (R5)(R6)
\Edge (R5)(R7)
\Edge (R6)(R8)
\Edge (R7)(R8)
\end{tikzpicture}
\end{center}

But \textsf{Sage} has knowledge of graph theory and you can use it to specify graphs
and determine various characteristics. For example:\\\\
\begin{sagesilent}
H= graphs.PetersenGraph()
H.set_latex_options(scale=3.5,graphic_size=(2.1,2.1))
Chi = H.chromatic_number(algorithm="DLX")
Beta = H.independent_set()
\end{sagesilent}
\noindent The Petersen graph below has $\sage{H.order()}$ vertices and
$\sage{H.size()}$ edges.\\\\
\begin{center}
\begin{tikzpicture}
\GraphInit[vstyle=Normal]
\SetVertexNormal[Shape=circle,LineWidth = 1pt]
\tikzset{EdgeStyle/.append style = {color = blue!60, line width=1pt}}
\sage{H}
\end{tikzpicture}
\end{center}
\vspace{5pt}
The chromatic number is $\chi(G)=\sage{Chi}$. The maximum size independent 
set is $\beta(G)=\sage{len(Beta)}$. One such set is $\sage{Beta}$. The 
maximum size clique has $\omega(G)=\sage{H.clique_number()}$ vertices; 
e.g., $\sage{H.clique_maximum()}$. The diameter is $\sage{H.diameter()}$
and the radius is $\sage{H.radius()}$.
\end{document}

在Sagemath Cloud中运行的结果是:在此处输入图片描述

如果您放大图片,您会发现 Sage 已经为您计算了图形的参数——这是一种避免重要文档中出现错误的好方法。

答案3

您可以将 Geogebra 中绘制的任何内容导出为 tikz 代码,请参阅本教程,https://www.sharelatex.com/blog/2013/08/28/tikz-series-pt2.html

相关内容