用tikz绘图,指定参数值,只能生成部分图形,全部改成数值后,可以生成正确图形。请指点。

2020-06-03 11:28发布

## 编译环境 操作系统 * [x] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `2...

## 编译环境 操作系统 * [x] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `2019` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 用tikz绘图,指定参数值,只能生成部分图形,全部改成数值后,可以生成正确图形。请指点。 ```markdown \begin{tikzpicture} \def\ra{0.4} %利用参数定义小,大椭圆,长度。 \def\rb{0.8} \def\Ra{0.8} \def\Rb{1.6} \def\a{3.8} \draw[dotted] (0,0) ellipse (\ra and \rb); \draw (0,\Rb) arc (90: 270: \Ra and \Rb); \draw [dotted](0,-\Rb) arc (-90: 90: \Ra and \Rb); \draw (3.8,0) ellipse (0.4 and 0.8); \draw (3.8,0) ellipse (0.8 and 1.6); \draw (0,\Rb) -- (\a,\Rb); \draw (0,-\Rb) -- (\a,-\Rb); \draw [<->](0,-\Rb-0.3) -- node[below] {a}(\a,-\Rb-0.3); \draw [red](\a,0) --node[above] {$r$} (\a+\ra,0); \draw [red](\a,0) --node[left] {$R$} (\a,-\rb); \filldraw[fill=teal,draw=black] (\a,0) circle (1pt); \end{tikzpicture} ``` ```markdown \begin{tikzpicture} \draw[dotted] (0,0) ellipse (0.4 and 0.8); \draw (0,1.6) arc (90: 270: 0.8 and 1.6); \draw [dotted](0,-1.6) arc (-90: 90: 0.8 and 1.6); \draw (3.8,0) ellipse (0.4 and 0.8); \draw (3.8,0) ellipse (0.8 and 1.6); \draw (0,1.6) -- (3.8,1.6); \draw (0,-1.6) -- (3.8,-1.6); \draw [<->](0,-1.6-0.3) -- node[below] {a}(3.8,-1.6-0.3); \draw [red](3.8,0) --node[above] {$r$} (3.8+0.4,0); \draw [red](3.8,0) --node[left] {$R$} (3.8,-0.8); \filldraw[fill=teal,draw=black] (3.8,0) circle (1pt); \end{tikzpicture} ```
3条回答
zhaochongbin
2020-06-03 11:55
用大括号把 `and` 两边的命令括起来 ```tex \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \def\ra{0.4} %利用参数定义小,大椭圆,长度。 \def\rb{0.8} \def\Ra{0.8} \def\Rb{1.6} \def\a{3.8} \draw[dotted] (0,0) ellipse ({\ra} and {\rb}); \draw (0,\Rb) arc (90: 270: {\Ra} and {\Rb}); \draw [dotted](0,-\Rb) arc (-90: 90: {\Ra} and {\Rb}); \draw (3.8,0) ellipse (0.4 and 0.8); \draw (3.8,0) ellipse (0.8 and 1.6); \draw (0,\Rb) -- (\a,\Rb); \draw (0,-\Rb) -- (\a,-\Rb); \draw [<->](0,-\Rb-0.3) -- node[below] {a}(\a,-\Rb-0.3); \draw [red](\a,0) --node[above] {$r$} (\a+\ra,0); \draw [red](\a,0) --node[left] {$R$} (\a,-\rb); \filldraw[fill=teal,draw=black] (\a,0) circle (1pt); \end{tikzpicture} \end{document} ```

一周热门 更多>