TikZで四角形を書く
code:draw.tikz(tex)
\begin{document}
\begin{tikzpicture}
\clip (-1,-1) rectangle (2,2);
\draw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
\end{tikzpicture}
\end{document}
cycleでパスを閉じる
太さはdefaultでthick(=0.8pt)と同じ
なので
$ \draw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
は
$ \draw thick (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle; と等価である
code:draw2.tikz(tex)
\begin{document}
\begin{tikzpicture}
\clip (-1,-1) rectangle (4,2);
\draw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
\draw thick (2,0) -- (2,1) -- (3,1) -- (3,0) -- cycle; \end{tikzpicture}
\end{document}
うーん?太さが違うように見える……
defaultだと0.4ptになってしまうみたい
太さの指定方法
preset
ultra thin 0.1pt
very thin 0.2pt
thin 0.4pt
defaultもこれっぽい
semithick 0.6pt
thick 0.8pt
very thick 1.2pt
ultra thick 1.6pt
code:width-preset.tikz(tex)
\begin{document}
\begin{tikzpicture}
\clip (-0.5,-0.5) rectangle (6,3);
\drawultra thick (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle; \drawvery thick (0+1.5,0) -- (0+1.5,1) -- (1+1.5,1) -- (1+1.5,0) -- cycle; \drawthick (0+3,0) -- (0+3,1) -- (1+3,1) -- (1+3,0) -- cycle; \drawsemithick (0+4.5,0) -- (0+4.5,1) -- (1+4.5,1) -- (1+4.5,0) -- cycle; \drawultra thin (0,0+1.5) -- (0,1+1.5) -- (1,1+1.5) -- (1,0+1.5) -- cycle; \drawvery thin (0+1.5,0+1.5) -- (0+1.5,1+1.5) -- (1+1.5,1+1.5) -- (1+1.5,0+1.5) -- cycle; \drawthin (0+3,0+1.5) -- (0+3,1+1.5) -- (1+3,1+1.5) -- (1+3,0+1.5) -- cycle; \draw (0+4.5,0+1.5) -- (0+4.5,1+1.5) -- (1+4.5,1+1.5) -- (1+4.5,0+1.5) -- cycle;
\end{tikzpicture}
\end{document}
相対座標指定
rectangleで座標をつなぐ
\draw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;を\draw (0,0) rectangle (1,1);と略記できる
code:rectangle.tikz(tex)
\begin{document}
\begin{tikzpicture}
\clip (-0.5,-0.5) rectangle (1.5,1.5);
\draw (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}