2

If I draw a triangle in stand alone, how do I label my drawing? I am able to draw my picture but I cant label any of the angles or sides.

2 Answers2

2

With angles library, it is easy.

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{angles}
\begin{document}
  \begin{tikzpicture}
     \draw (0,0) coordinate (A) -- node[midway,below]{A} (5,0) coordinate (B)
        -- node[midway,right]{B} (2.5,5) coordinate (C) -- node[midway,left]{C} (A)
     pic [fill=olive!50] {angle = A--B--C}
     pic [draw,<-,red,thick,angle radius=5mm] {angle = C--B--A}
     pic [draw,<-,red,thick,angle radius=5mm] {angle = B--A--C}
     pic [draw,<-,red,thick,angle radius=5mm] {angle = A--C--B};
  \end{tikzpicture}
\end{document}

enter image description here

2

It is not exactly clear what your question is. But, I am guessing that you want to alter the a diagram in the main text that is done as a standalone diagram. If that is the case, you could make use of \providecommand and .provide style (as per the link in the References below) to define the standalone diagram.

The MWE below consists of three files:

  1. MyPreamble.sty which contains the preamble for both the main file and the standalone figure.
  2. MyTriangle.tex which is the standalone figure.
  3. The main .tex file which \inputs MyTriangle.tex three times with altered the settings.

The first figure is the default figure, the second shows a case where you don't want any text labels, and the third shows how to change the labels. Also illustrated is how to change the style of the figure:

enter image description here

References:

Code:

\documentclass{article}

\usepackage{filecontents} \begin{filecontents}{MyPreamble.sty} \usepackage{standalone} \usepackage{tikz} %% https://tex.stackexchange.com/questions/22640/is-there-something-like-providetikzstyle-similar-to-providecommand \tikzset{/handlers/.provide style/.code={% \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{}% {\pgfkeys {\pgfkeyscurrentpath /.code=\pgfkeysalso {#1}}}% }} \end{filecontents}

\begin{filecontents*}{MyTriangle.tex} \documentclass[tikz,border=5pt]{standalone} \usepackage{MyPreamble}

\begin{document}
\providecommand*{\SideALabel}{$A$}%
\providecommand*{\SideBLabel}{$B$}%
\providecommand*{\SideCLabel}{$C$}%

\tikzset{My Line Style/.provide style={thick, black}}
\tikzset{My Node Style/.provide style={}}

\begin{tikzpicture}[scale=0.5]
    \draw [My Line Style] (0,0) coordinate (A) 
        -- node[midway,below, My Node Style] {\SideALabel} (5,0)   coordinate (B)
        -- node[midway,right, My Node Style] {\SideBLabel} (2.5,5) coordinate (C) 
        -- node[midway,left,  My Node Style] {\SideCLabel} (A);
\end{tikzpicture}
\end{document}

\end{filecontents*}

\usepackage{MyPreamble}

\begin{document} \begin{minipage}{0.3\linewidth} \input{MyTriangle.tex}% \end{minipage} \begin{minipage}{0.3\linewidth} \tikzset{My Line Style/.provide style={ultra thick, draw=blue, fill=yellow}} \tikzset{My Node Style/.provide style={text=white}} \input{MyTriangle.tex}% \end{minipage} \begin{minipage}{0.3\linewidth} \newcommand{\SideALabel}{$X$}% \newcommand{\SideBLabel}{$Y$}% \newcommand*{\SideCLabel}{$Z$}% \tikzset{My Line Style/.provide style={ultra thick, draw=none, fill=green}} \tikzset{My Node Style/.provide style={text=red}} \input{MyTriangle.tex}% \end{minipage} \end{document}

Peter Grill
  • 223,288