Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
4  
And which code exactly are you using? How are you drawing your image? Please add a complete, minimal version of the document showing the relevant settings. –  Gonzalo Medina Apr 28 at 0:10
    
Why would standalone make a difference? Does it work when you don't compile it with standalone? –  cfr Apr 28 at 1:28
    
tex.stackexchange.com/a/173270/19356 should help you. –  Who is crazy first Apr 28 at 2:17

2 Answers 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

share|improve this answer

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}
    %% http://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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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