3

I have some code generating a triangle as below:

\nonstopmode
\documentclass{article}
\usepackage{scrextend}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows, positioning, calc, intersections, arrows.meta}
\usepackage{gensymb}
\changefontsizes[12pt]{10pt}
\usepackage[a4paper, left=0.7in,right=0.7in,top=1in,bottom=1in]{geometry}
\pagenumbering{gobble}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\definecolor{red_1}{rgb}{0.9,0,0}
\section*{\centering{Question Sheet}}
\vspace{10mm}


\begin{tikzpicture}[scale=1.0,thick]
\coordinate (B) at (2.5,5.5);
\coordinate (A) at (-1,9.0);
\coordinate (C) at (-4,-1.0);
\tkzMarkAngle[size=3cm,color=red_1,line width=1.5,opacity=0.5](B,C,A);
\tkzMarkRightAngle[size=0.5,color=red_1,line width=1,opacity=0.5](A,B,C);
\draw (A)--(B)--(C)--cycle;
\node at (-3.1609768069701802,0.4047040536671167) {$28.3\degree$};
\node[above,color=black] at (-2.5,4.0) {$$10.4$cm\hspace{40pt}$};
\node[below,color=black] at (-0.75,2.25) {$\hspace{40pt}$9.2$cm$};
\node[right,color=black] at (2.5,5.5) {$$B$$};
\node[below,color=black] at (-4.0,-1.0) {$$C$\hspace{20pt}$};
\node[above,color=black] at (-1.0,9.0) {$$A$$};
\end{tikzpicture}\\




\end{document}

but when I compile it, the \tkzMarkAngle[size=3cm,color=red_1,line width=1.5,opacity=0.5](B,C,A); throws the errors "Missing number, treated as zero. ...=red_1,line width=1.5,opacity=0.5](B,C,A)" and "Illegal unit of measure (pt inserted). ...=red_1,line width=1.5,opacity=0.5](B,C,A)". I can't see where these are coming from, and I have another 9 triangles written with identical structure, and only the values of the points and labels changing and they work fine. What is causing this?

Here's a picture of the triangle:

enter image description here

and one of the others:

enter image description here

and the code for the second triangle:

\nonstopmode
\documentclass{article}
\usepackage{scrextend}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows, positioning, calc, intersections, arrows.meta}
\usepackage{gensymb}
\changefontsizes[12pt]{10pt}
\usepackage[a4paper, left=0.7in,right=0.7in,top=1in,bottom=1in]{geometry}
\pagenumbering{gobble}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\definecolor{red_1}{rgb}{0.9,0,0}
\section*{\centering{Question Sheet}}
\vspace{10mm}

\begin{tikzpicture}[scale=1.0,thick]
\coordinate (A) at (-3.076923076923077,8.384615384615385);
\coordinate (C) at (-2,3.0);
\coordinate (B) at (4,9.8);
\tkzMarkAngle[size=2cm,color=red_1,line width=1.5,opacity=0.5](A,B,C);
\tkzMarkRightAngle[size=0.5,color=red_1,line width=1,opacity=0.5](C,A,B);
\draw (A)--(B)--(C)--cycle;
\node at (2.9151888829770587,9.175118149666678) {$37.3\degree$};
\node[below,color=black] at (1.0,6.4) {$\hspace{40pt}$9.1$cm$};
\node[above,color=black] at (0.46153846153846156,9.092307692307692) {$$7.2$cm\hspace{40pt}$};
\node[left,color=black] at (-3.076923076923077,8.384615384615385) {$$A$$};
\node[above,color=black] at (4.0,9.8) {$\hspace{20pt}$B$$};
\node[below,color=black] at (-2.0,3.0) {$$C$$};
\end{tikzpicture}\\

\end{document}
2

Not really sure why that happens (the error message looked like it came from some calculation involving atan), but you can use the features of the angles and quotes libraries of TikZ instead, and do

\pic[draw,red,angle eccentricity=0.75,angle radius=2.5cm,"\ang{28.3}" text=black] {angle=B--C--A};

In the code below I suggest a modification of the code. Labels for corners are added as a label for the coordinate, instead of separate nodes at explicit coordinates. Labels for sides are added as nodes placed during the drawing of the sides, again instead of separate nodes at explicit coordinates.

I used siunitx to typeset both the angle (\ang{28.3}) and the lengths (\SI{9.1}{\cm}). The way the lengths were typeset was actually wrong, with the unit in math italics. And the \hspace in a couple of the nodes is not really necessary, one can place the node better instead.

The two triangles looks like this with the code below:

triangles from code

\documentclass{article}
\usepackage{scrextend}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{angles,quotes, arrows.meta}
\usepackage{siunitx}
\definecolor{red_1}{rgb}{0.9,0,0}

% redefine \section instead of manually adding \centering
\usepackage{titlesec}
\titleformat*{\section}{\Large\bfseries\centering}
\begin{document}
\section*{Question Sheet}

\begin{tikzpicture}[scale=1.0,thick]
\coordinate [label=right:$B$] (B) at (2.5,5.5);
\coordinate [label=above:$A$] (A) at (-1,9.0);
\coordinate [label=below:$C$] (C) at (-4,-1.0);

% mark angle
\pic[draw,red_1,angle eccentricity=0.75,angle radius=2.5cm,"\ang{28.3}" text=black] {angle=B--C--A};

\tkzMarkRightAngle[size=0.5,color=red_1,line width=1,opacity=0.5](A,B,C);

\draw (A) -- 
      (B) -- node[below right] {\SI{9.2}{\cm}} 
      (C) -- node[above left] {\SI{10.4}{\cm}} cycle;
\end{tikzpicture}

\begin{tikzpicture}[scale=1.0,thick]
\coordinate [label=above left:$A$] (A) at (-3.076923076923077,8.384615384615385);
\coordinate [label=below:$C$] (C) at (-2,3.0);
\coordinate [label=above right:$B$] (B) at (4,9.8);

\tkzMarkAngle[size=2cm,color=red_1,line width=1.5,opacity=0.5](A,B,C);
\tkzLabelAngle[pos=1](A,B,C) {\ang{37.3}}

\tkzMarkRightAngle[size=0.5,color=red_1,line width=1,opacity=0.5](C,A,B);

\draw (A) -- node[above left] {\SI{7.2}{\cm}}
      (B) -- node[below right] {\SI{9.1}{\cm}}
      (C) -- cycle;
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.