[Tex/LaTex] Best way to create this image, square and angle

tikz-pgf

I have just started looking into tikz, and trying to create the simple image below. I took a stab at it but could not quite do it.

enter image description here

ABCD is a square and E is the midpoint on DC and F is the midpoint of BC

Ofcourse the labels should be a tad smaler, and closer to the actual figure. I am just trying to learn tikz, so a few examples how to create the image beautifuly would truly help me. Here is my attempt at it. Only using the simple tikzpackage.

I had mainly two problems creating this image

1) How do one place points in tex, and anchor text to them?

2) How do one create the angle… I know it is some arc, but yeah

\begin{figure}[h!] \centering
\begin{tikzpicture}[scale=3]
\coordinate [label=left:\textcolor{blue}{$A$}] (A) at (0.,0);
\coordinate [label=right:\textcolor{blue}{$B$}] (B) at (1,0);
\coordinate [label=right:\textcolor{blue}{$C$}] (C) at (1,1);
\coordinate [label=left:\textcolor{blue}{$D$}] (D) at (0,1);
\draw (0,0) -- (1,0); 
\draw (0,0) -- (0,1);
\draw (1,0) -- (1,1);
\draw (0,1) -- (1,1);
\draw (0,0) -- (1,0.5);
\draw (0,0) -- (0.5,1);

\end{tikzpicture}
\end{figure}

I also guess there is some simple way to do this, like a built in square command or something…

My stab at creaing the square

Best Answer

Below is a solution using tkz-euclide (as Regis da Silva mentioned in a comment that I only now saw).

Edit: I've changed it slightly. Here you can change the size of the square simply by changing the position of point B. The reason that I didn't use tkzDrawPolygon to draw the triangle, is that the corners would extend a little outside the rectangle. Uncomment that line to see what I mean. Also, if the position of B is (1,0) the arc showing the angle is too large, and then you will want to uncomment the line size=0.4.

\documentclass{article} 
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
    \tkzDefPoint(0,0){A}  \tkzLabelPoint[below left](A){A}
    \tkzDefPoint(3,0){B}  \tkzLabelPoint[below right](B){B}
    \tkzDefSquare(A,B)    \tkzGetPoints{C}{D}
    \tkzDrawSquare(A,B)
    \tkzLabelPoint[above right](C){C} \tkzLabelPoint[above left](D){D}
    \tkzDefMidPoint(C,D) \tkzGetPoint{E}  \tkzLabelPoint[above](E){E}
    \tkzDefMidPoint(B,C) \tkzGetPoint{F}  \tkzLabelPoint[right](F){F}
    \tkzDrawSegments(A,E E,F A,F)
    %\tkzDrawPolygon(A,E,F)
    \tkzDrawPoints[fill=black](E,F)
    \tkzMarkAngle[fill=red,%
                 %size=0.4,   % for small squares you may want to use this
                 opacity=0.4](F,A,E)
    \tkzLabelAngle[pos=1.2](E,A,F){$\alpha$}
\end{tikzpicture}
\end{document}

enter image description here

The problem with this package is that the manual is only in French, as far as I know.


You can mix this with normal TikZ, code, so wh1t3's code can be modified slightly, using tkz-euclide to draw the arc.

Note that instead of using \textcolor for all the labels, you can edit the every label style. The updated example shows this, as well as how to change the color of a single label (note the extra set of braces).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
    \noindent
    \begin{tikzpicture}[scale=3,every label/.style={color=blue}]
        \coordinate [label=left:$A$] (A) at (0,0);
        \coordinate [label=right:$B$] (B) at (1,0);
        \coordinate [label=right:$C$] (C) at (1,1);
        \coordinate [label=left:$D$] (D) at (0,1);
        \coordinate [label=above:$E$] (E) at ($(D)!.5!(C)$);
        \coordinate [label={[black]right:$F$}] (F) at ($(B)!.5!(C)$);
        \draw (A) rectangle (C);
        \draw [fill] (A) -- (E) circle[radius=.5pt] 
                         -- (F) circle[radius=.5pt] -- (A);
        \tkzMarkAngle[fill=red,opacity=.5,size=.3](F,A,E)
        \tkzLabelAngle[pos=.4](E,A,F){$\alpha$}
    \end{tikzpicture}
\end{document}

enter image description here