Latex中TikZ初步使用
生活随笔
收集整理的這篇文章主要介紹了
Latex中TikZ初步使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
## 線段和點
?\documentclass{article}\usepackage{tikz}\begin{document}\begin{tikzpicture} \draw[gray, thick] (-1,2) -- (2,-4); ?% 畫線段:gray和thick確定線顏色和線粗,后面兩個坐標確定線段端點\draw[gray, thick] (-1,-1) -- (2,2);\filldraw[black] (0,0) circle (2pt) ?%畫點(fill表示填充),black:填充顏色,2pt:半徑,兩個像素node[anchor=west]{Intersection point}; ?% 畫一個node(其實是邊框),點在邊框的west方向,邊框內容為Intersection point\end{tikzpicture}\end{document}路徑path
?\documentclass{article}\usepackage{tikz}\begin{document}\begin{tikzpicture}?\draw (-2,0) -- (2,0);\filldraw [gray] (0,0) circle (2pt);\draw (-2,-2) .. controls (0,0) .. (2,-2); % 繪制Bézier curve:(-2, -2)和(2, -2)為端點,(0, 0)為控制點,可以理解為吸引點,來確定曲線的曲度\draw (-2,2) .. controls (-1,0) and (1,0) .. (2,2);% 繪制Bézier curve:(-2, 2)和(2, 2)為端點,(-2, 0)和(1, 0)為控制點,可以理解為吸引點,來確定曲線的曲度?\end{tikzpicture}\end{document}圓、橢圓和多邊形
?\documentclass{article}\usepackage{tikz}\begin{document}\begin{tikzpicture}\filldraw[color=red!60, fill=red!5, very thick](-1,0) circle (1.5); % 繪制圓,color:圓環顏色60%red;fill:填充顏色;very thick:圓環厚度,(-1, 0)表示圓心坐標,circle:圓的半徑\fill[blue!50] (2.5,0) ellipse (1.5 and 0.5); % 繪制橢圓:\draw[ultra thick, ->] (6.5,0) arc (0:220:1); ?% 繪制圓的曲線,->線的尾部加箭頭,(6.5, 0)表示起點坐標;arc確定形狀,(0:220:1)表示起點角度,終點角度和半徑\end{tikzpicture}\end{document}fill和filldraw的區別是一個填充相同顏色,一個可以填充其他顏色,其他部分基本一致
fill[參數]:參數有顏色
filldraw[參數]:參數有color, fill, 邊緣厚度
fill/filldraw[...]+中心點+形狀(circle/elipse)(形狀參數)
?\documentclass{article}\usepackage{tikz}\begin{document}\begin{tikzpicture}\draw[blue, very thick] (0,0) rectangle (3,2); %繪制矩形:起點坐標(0, 0),長寬:3, 2\draw[orange, ultra thick] (4,0) -- (6,0) -- (5.7,2) -- cycle; % 多邊形:需要多點坐標,cycle表示封閉圖形\end{tikzpicture}\end{document}Diagram
?\documentclass{article}\usepackage{tikz}\usetikzlibrary{positioning}\begin{document}\begin{tikzpicture}[roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm}, % minimum size表示圖形大小squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},] ?% 確定不同節點類型,屬性%Nodes 繪制節點\node[squarednode] ? ? (maintopic) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{2}; ?% 繪制2節點,名稱為maintopic,是一個方形節點\node[roundnode] ? ? ? (uppercircle) ? ? ? [above=of maintopic] {1}; ?% 繪制1節點,是一個圓形節點,above表示在maintopic節點的上方\node[squarednode] ? ? (rightsquare) ? ? ? [right=of maintopic] {3}; % 繪制3節點,是一個方形節點\node[roundnode] ? ? ? (lowercircle) ? ? ? [below=of maintopic] {4}; % 繪制4節點,是一個圓形節點?%Lines 繪制節點之間的連線\draw[->] (uppercircle.south) -- (maintopic.north); ?% 確定起點和終點\draw[->] (maintopic.east) -- (rightsquare.west);\draw[->] (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.east); ?% down和right的表示連接3和4的切線方向\end{tikzpicture}\end{document}上述的相對位置確定是根據right = of ***,位置也可以通過坐標at來確定
?\documentclass{article}\usepackage{tikz}\usetikzlibrary{positioning}\begin{document}\begin{tikzpicture}[roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm},squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},whitesquarednode/.style={rectangle, minimum size=5mm},scale = 0.8, ?% 整張圖進行縮放]%Nodes\node[squarednode] ? ? (maintopic) ? at (0, 0) ?{2}; ?% 用at確定node位置\node[roundnode] ? ? ? (uppercircle) ? ? at (0, 2) {1};\node[squarednode] ? ? (rightsquare) ? at (2, 0) {3};\node[roundnode] ? ? ? (lowercircle) ? at (0, -2) {4};% \node[whitesquarednode] (5) at (0, -1) {5};\node[whitesquarednode](label) at (0, -1) {label};?%Lines\draw[->] (uppercircle.south) -- (maintopic.north);\draw[->] (maintopic.east) -- (rightsquare.west);\draw[dashed, green, very thick] (rightsquare.south) .. controls +(down:10mm) and +(right:7mm) .. (lowercircle.east); ?% dashed:線型\end{tikzpicture}\end{document}總結
以上是生活随笔為你收集整理的Latex中TikZ初步使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人工智能——搜索策论2
- 下一篇: 电脑配置GPU加速器||电脑配置CUDA