
我有一個問題,我是碩士生,我正在用 LaTeX 寫論文(圖論)。
誰能幫我找到一個線上網站來繪製圖表,然後在LaTeX中線上插入程式碼?
答案1
以下是在 R 中使用 igraph 套件並使用 knit 和 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
您可以考慮免費註冊Sagemath 雲帳戶,讓您能夠使用電腦代數系統 Sage 以及sagetex
LaTeX 軟體包;文件這裡。 Sage 具有圖論知識;例如命名圖,圖表參數, 乃至乳膠選項。這表示您可以使用 Sage 建立圖表tikz
或使用 Sage 的強大功能來處理細節。這是一個例子:
\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}
如果放大圖片,您會發現 Sage 已經為您計算了圖表的參數——這是避免重要文件中出現錯誤的好方法。
答案3
您可以將 Geogebra 中繪製的任何內容匯出為 tikz 程式碼,請參閱本教學課程,https://www.sharelatex.com/blog/2013/08/28/tikz-series-pt2.html