5

My goal is to draw a figure exactly like this enter image description here The best I could do coding this was:

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usepackage{float}

\begin{document}

\begin{tikzpicture}      

    \draw (1, 0) to (1, 4); 
    \draw (1, 0) to (4, 0); 
    \draw (1, 4) to (4, 0);

\end{tikzpicture}

\begin{tikzpicture}

    \draw (1, 0) to (1, 3);
    \draw (1, 0) to (3, 0);
    \draw (1, 3) to (3, 0);

\end{tikzpicture}    

\end{document}

Which ends up looking like this. I tried putting in the values and angle points but it ended up looking much worse, so I omitted them: enter image description here

So how do I get my figure to look exactly like the first figure? If it means anything, I'm using a MacBook Pro and I'm using the TexShop application.

6

Welcome to TeX-SE! The issue you are seeing is caused by the fact that an empty line tells TeX to start a new paragraph. So all you need to do is to remove the empty line. Here I go a slightly different route and put the second triangle in a scope that is used to move it to the right. This allows you to more easily control the distance between the triangles, and their vertical relative alignment. Please note also that it is advantageous to draw them in one stretch and close them with -- cycle because then the line joins look better.

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usepackage{float}

\begin{document}

\begin{tikzpicture}
    \draw (1, 0) node[below left]{$A$} -- node[midway,left]{$x+29$}
    (1, 4) node[above left] {$B$} 
    --  (4, 0) node[below right]{$C$} -- node[midway,below]{$21$}
    cycle; 
\begin{scope}[xshift=5cm,yshift=0.5cm]
    \draw (1, 0) node[below left]{$D$} 
    --  node[midway,left]{$12$} (1, 3)
    node[above left]{$E$} 
    -- (3, 0) node[below right]{$F$} -- node[midway,below]{$x$}
    (1,0)-- cycle   ;
\end{scope}
\end{tikzpicture}    

\end{document}

enter image description here

  • Thank you! That did just the job. I'll definitely keep the scope and shift and cycle stuff in my arsenal. I'm new to LaTeX, so I'm just getting the hang of it at the moment. – Lex_i Apr 6 at 0:22
  • @Lex_i You're welcome! (Please note also that the absolute coordinates do not have a real meaning, i.e. instead of \draw (1, 0) node[below left]{$A$} -- node[midway,left]{$x+29$} (1, 4) node[above left] {$B$} -- (4, 0) node[below right]{$C$} -- node[midway,below]{$21$} cycle; you could also use \draw (0, 0) node[below left]{$A$} -- node[midway,left]{$x+29$} (0, 4) node[above left] {$B$} -- (3, 0) node[below right]{$C$} -- node[midway,below]{$21$} cycle;. – marmot Apr 6 at 0:24
  • Even if the problem of the question is trivial, the question is very well formulated, with a complete MWE. Even if the answer is simple, I think it could be useful. Not much is needed to trasform a banality in a future easily searchable help. These are not the things I was referring to in Meta. – CarLaTeX Apr 6 at 5:07
3

an alternative, using relative coordinates tikz libraryquotes for labeling lines in triangles:

\documentclass{article}
\usepackage{amsmath,amssymb} % amsfonts is loaded by amsymb
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}

\begin{tikzpicture}
    \draw (0, 0) node[below] {A} to["$x+29$"] ++ (0, 4) node[above] {B}
                                 to ++ (3,-4) node[below] {C}
                                 to["$21$"] cycle;
    \draw (5,.5) node[below] {D} to["$12$"] ++ (0, 3) node[above] {E}
                                 to ++ (2,-3) node[below] {F}
                                 to["$x$"] cycle;
\end{tikzpicture}

\end{document}

enter image description here

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.