1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Tikzで描く例

Posted at

こんな図を描きたいとする。

名称未設定.png

使うパッケージ

\usepackage{tikz}
\usetikzlibrary{intersections, calc, arrows}

黒塗り三角形を2つ横に並べるコードを描いた。
計算にはcalcを用いた。

コマンド定義

三角形を描くコマンドを作った。座標を定義して、座標間の関係を定義してfillで塗っている。

\newcommand{\myTriangle}[1]{
\coordinate (myA) at ($#1+(0,0)$);
\coordinate (myB) at ($#1+(1,1)$);
\coordinate (myC) at ($#1+(2,0)$);
\fill (myA)--(myB)--(myC)--cycle;}

 Tikzの本体

tikzpictureのbeginとend内に諸々の命令を描いていく。

\begin{tikzpicture}
...
\end{tikzpicture}

ベクトルの定義

ベクトルを定義して、三角形をそのベクトルを足すことで場所を定義

\coordinate (R) at (2,0);
\coordinate (U) at (0,1);
\coordinate (LD) at (-1,-1);
\coordinate (RD) at (1,-1);

\coordinate (A) at (0,0);
\coordinate (B) at ($(A)+3*(R)$);
\coordinate (C) at ($(A)+3*0.5*(R)+4*(U)$);

三角形の描画

コマンドを用いて三角形を描画

\myTriangle{(A)}
\myTriangle{(B)}
\myTriangle{(C)}

足の描画

ベクトルを足し引きすることで足の座標を指定し、線を引く

\draw ($(A)+0.5*(R)+1*(U)$) -- ($(C)$);
\draw ($(B)+0.5*(R)+1*(U)$) -- ($(C)+(R)$);
\draw ($(A)$) -- ($(A)-0.5*(R)-4*(U)$);
\draw ($(A)+(R)$) -- ($(A)+(R)+0.5*(R)-4*(U)$);
\draw ($(B)$) -- ($(B)-0.5*(R)-4*(U)$);
\draw ($(B)+(R)$) -- ($(B)+(R)+0.5*(R)-4*(U)$);

うまく定義すれば複雑な描画もできるようになる。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?