另一场考试,另一张图片。我正在尝试在 TikZ 中创建以下图像
现在。我正在寻找一些关于我的代码的反馈。我正在努力尽快学习 TikZ,但我仍然觉得我做的事情过于复杂或效率极低。
我的主要问题是找到在左侧创建线段的最佳方法。我该怎么做?将它们分开并在中间放置文本只是无用功。
以下是我的尝试。请不要太在意,因为它真的很糟糕。
\documentclass[10pt,a4paper]{article}
\usepackage[dvipsnames*,svgnames]{xcolor}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{mathtools}
\begin{document}
\begin{tikzpicture}[scale=5]
\tkzDefPoint(-0.1,0){P}
\tkzDefPoint(0,0){O}
\tkzDefPoint(1.2,0){A}
\tkzDefPoint(0,0.8){B}
\tkzDefPoint(0,1.6){C}
\tkzDefPoint(1.2,0){G}
\tkzDefPoint(1.2,.83){U}
\tkzDefPointBy[rotation= center B angle 110](C) \tkzGetPoint{D}
\tkzDefPointBy[rotation= center O angle 35](G) \tkzGetPoint{E}
\tkzDefMidPoint(B,E) \tkzGetPoint{M1}
\tkzDefMidPoint(C,E) \tkzGetPoint{M2}
\tkzMarkAngle[thick,scale=0.5,fill=black!20!white](A,O,E)
\tkzMarkAngle[thick,scale=0.4,fill=black!20!white](E,B,C)
\tkzDrawSegment[thick](P,A)
\draw[thick](-0.6,0)--(-0.4,0);\draw[thick](-0.6,1.6)--(-0.4,1.6);
\draw[thick](-0.1,0.8)--(-0.3,0.8);\draw[thick](-0.1,1.6)--(-0.3,1.6);
\draw[thick](-0.2,1.6)--(-0.2,1.3);\draw[thick](-0.2,0.8)--(-0.2,1.1);
\draw[thick](-0.5,0.0)--(-0.5,0.6);\draw[thick](-0.5,0.8)--(-0.5,1.6);
\tkzDrawSegment[ultra thick,Goldenrod,dashed](O,U)
\tkzDrawSegments[ultra thick](O,C B,E)
\tkzDrawSegment[ultra thick,Magenta](C,E)
\tkzLabelPoint[left=-.55](-0.2,1.2){$0.8$ m} ;
\tkzLabelPoint[left=-.65](-0.5,0.7){$\stackrel{\text{\large Vindu}}{1.6 \text{m}}$} ;
\tkzLabelPoint[above=0.2](M1){Arm} ;
\tkzLabelPoint[below left](M1){$0.8$m} ;
\tkzLabelPoint[above=0.2,right, Magenta](M2){$\mathit{\mathbf{L}}$} ;
\tkzLabelPoint[above=1,Magenta](M2){\bfseries Markiseduk} ;
\tkzLabelPoint[below=1.75,left,Goldenrod](E){\bfseries Solstr\aa le} ;
\tkzLabelAngle[pos=0.3](A,O,E){$u$}
\tkzLabelAngle[pos=0.225](E,B,C){$v$}
\end{tikzpicture}
\end{document}
我的结果…
答案1
但tkz-euclide
我注意到一个错误,因为我需要用它pos=0.4
垂直放置标签(??)
版本 2 带有选项 `|-|``
\documentclass[10pt,a4paper]{article}
\usepackage[dvipsnames*,svgnames]{xcolor}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{mathtools}
\begin{document}
\begin{tikzpicture}[scale=5]
\tkzDefPoint(-0.1,0){P}
\tkzDefPoint(0,0){O}
\tkzDefPoint(1.2,0){A}
\tkzDefPoint(0,0.8){B}
\tkzDefPoint(0,1.6){C}
\tkzDefPoint(1.2,0){G}
\tkzDefPoint(1.2,.83){U}
\tkzDefPointBy[rotation= center B angle 110](C) \tkzGetPoint{D}
\tkzDefPointBy[rotation= center O angle 35](G) \tkzGetPoint{E}
\tkzDefShiftPoint[B](-0.2,0){B'}
\tkzDefShiftPoint[C](-0.2,0){C'}
\tkzDefShiftPoint[O](-0.6,0){O''}
\tkzDefShiftPoint[C](-0.6,0){C''}
\tkzMarkAngle[thick,scale=0.5,fill=black!20!white](A,O,E)
\tkzMarkAngle[thick,scale=0.4,fill=black!20!white](E,B,C)
\tkzDrawSegment[thick](P,A)
\tkzDrawSegment[ultra thick,Goldenrod,dashed](O,U)
\tkzDrawSegments[ultra thick](O,C B,E)
\tkzDrawSegment[ultra thick,Magenta](C,E)
\tkzDrawSegments[|-|](B',C' O'',C'')
\tkzLabelSegment[above=0.2](B,E){Arm}
\tkzLabelSegment[below left](B,E){$0.8$m}
\tkzLabelSegment[above=0.2,right, Magenta](C,E){$\mathit{\mathbf{L}}$}
\tkzLabelSegment[above=1,Magenta](C,E){\bfseries Markiseduk}
\tkzLabelSegment[pos=.4,fill=white,inner sep=10pt](B',C'){$0.8$ m}
\tkzLabelSegment[pos=.4,fill=white,inner sep=10pt,align=center](O'',C''){\large Vindu\\$1.6$ m}
\tkzLabelPoint[below=1.75,left,Goldenrod](E){\bfseries Solstr\aa le}
\tkzLabelAngle[pos=0.3](A,O,E){$u$}
\tkzLabelAngle[pos=0.225](E,B,C){$v$}
\end{tikzpicture}
\end{document}
答案2
打破界限的另一种方法是画出它后节点并使其通过节点。当您这样做时,TikZ 会打破线路以“跳过”节点。举一个简单的例子:
\node (a) at (0,0) {a};
\draw (-3,0) -- (a) -- (3,0);
将产生:
---- a ----
(好吧,它看起来会比那好看一点!)
答案3
这是我本来会做的,但这绝对是个人喜好问题。您也可以尝试使用 -105 角度来获得满足您需求的不同输出。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\begin{document}
\begin{tikzpicture}[every node/.style={inner sep=0cm,outer sep=0cm},scale=5]
\draw[thick] (0,0) node (O) {} -- (0,0.8cm) node(M) {} -- (0,1.6cm) node (T) {} (0,0.8cm) -- ($(M)!1!-105:(T)$) node (tip){};
\draw (-2mm,0) -- node (justanode) {} (1.2cm,0);
\draw[magenta] (T) --node[near start,above right=2mm] {{\bfseries Markiseduk}} node[midway,above right=1mm] {L} (tip);
\draw[yellow!80!black,densely dashed] (O) -- node[midway,below right=1mm] {{\bfseries Solstr\aa le}} ($(O)!1.1!(tip)$);
\draw[|-|] ($(T) + (-2mm,0)$) -- node[fill=white,inner sep=1mm,midway] {0.8 m}($(M) + (-2mm,0)$);
\draw[|-|] ($(T) + (-4mm,0)$) -- node[fill=white,inner sep=1mm,text width=1cm,midway] {Vindu 1.6 m}($(O) + (-4mm,0)$);
\end{tikzpicture}
\end{document}
输出:
答案4
您只需添加具有白色背景的节点即可。您尝试创建的线条将由以下方式生成:
\tikz\path[draw] (0,0) -- ++(1,0) ++(-0.5,0) -- ++(0,-5) node[pos=0.5,fill=white] {Vindu} ++(.5,0) -- ++(-1,0);
要将其设置为两行,您需要添加文本对齐和宽度。如果您希望空白稍微大一些,请增加节点上的inner sep
。inner sep=6pt