3

Say I have the following triangle, which is a pretty standard figure:

\documentclass[border=3pt]{standalone}

\usepackage[ngerman]{babel}
\usepackage{tikz}

\usetikzlibrary{angles,quotes,babel}

\begin{document}
    \begin{tikzpicture}%
        \draw[thick,xshift=6cm] (0,0) coordinate(A) node[below left] {$\mathrm{A^{\prime}}$}
        -- (0:5cm) coordinate(B) node[pos=0.5, below] {$\mathrm{c^{\prime}}$} node[below right] {$\mathrm{B^{\prime}}$}
        -- (40:5cm) coordinate(C) node[pos=0.5, right] {$\mathrm{a^{\prime}}$} node[above] {$\mathrm{C^{\prime}}$}
        -- cycle node[pos=0.5,above left] {$\mathrm{b^{\prime}}$}
        pic["$\beta^\prime$",draw,thin,angle radius=0.5cm,angle eccentricity=1.3] {angle=C--B--A}
        pic["$\gamma^\prime$",draw,thin,angle radius=0.5cm,angle eccentricity=1.45] {angle=A--C--B}
        pic["$\alpha^\prime$",draw,thin,angle radius=0.5cm,angle eccentricity=1.5] {angle=B--A--C}
        ;
    \end{tikzpicture}
\end{document}

I placed the nodes manually and I have the problem that they have to be manually adjusted, if I rotate the figure. An example of how horrible it can get is if I add [rotate=180] after \begin{tikzpicture}.

I read the whole section on nodes in the manual, but didn't find an answer to this:

  1. For sides labels, is there a way to tell TikZ to place the nodes always half way (pos=0.5, but more "really 0.5") and especially to tell it to place it x pt (or mm) from the middle of the line in the direction of the perpendicular to the segment?

  2. For vertex labels, is there a way to tell TikZ to place the node x pt (or mm) from the vertex, on the bisector of the angle at that vertex?

If there were such a way, there would possibly remain to manually "swap" the position (for when the figure is upside/down), but this kind of geometric figures would always look nice.

3
  • I think that each node position you require is computable, but it needs a bit of work and a lot of code to add. Placing labels on sides is easy, for example with the calc library. Placing labels on angles might be trickier, but I think tkz-euclide package could help doing it.
    – SebGlav
    Feb 20 at 11:50
  • @SebGlav I'm surprised this code is not built-in in TikZ. There's a library for mostly anything with macros for extremely complicated things and it seems odd to me that for something as basic as this there's no mechanism.
    – Andyc
    Feb 20 at 11:56
  • Indeed! But you already had the answer for the vertices lables (using angles,quotes but on the other arc). See my answer below.
    – SebGlav
    Feb 20 at 12:16

2 Answers 2

3

As suplement to @SebGlav answer (+1), mostly off-topic:

  • used are quotes for labeling of edges
  • edge labels lie on edges (used option sloped)
  • defined common style for angle labels
  • all math variables in picture are set by
\everymath=\expandafter{\the\everymath\mathrm}
  • instead of ^#{prime} is used '
\documentclass[tikz, border=3pt]{standalone}
\usepackage[ngerman]{babel}
\usetikzlibrary{angles,
                calc,
                quotes,
                babel}
\tikzset{
Angle/.style = {draw, font=\footnotesize,
                angle radius=5mm,
                angle eccentricity=1.45},
every edge quotes/.style ={auto=right, rounded corners=5pt, inner sep=2pt},
        }


\begin{document}
    \begin{tikzpicture}
\everymath=\expandafter{\the\everymath\mathrm}
%
\draw[thick]    (0,0) coordinate (A)    to["$c'$"]   coordinate (c)
                (5,1) coordinate (B)    to["$a'$"]     coordinate (a)
                (2,3) coordinate (C)    to["$a'$"]     coordinate (b)
                cycle;
\path   pic[Angle, "$\beta'$"]  {angle=C--B--A}
        pic[Angle, "$\gamma'$"] {angle=A--C--B}
        pic[Angle, "$\alpha^\prime$"] {angle=B--A--C};
\path   (A) -- ($(A)!3mm!180:(a)$) node {A}
        (B) -- ($(B)!3mm!180:(b)$) node {B}
        (C) -- ($(C)!3mm!180:(c)$) node {C};
    \end{tikzpicture}

    \begin{tikzpicture}[rotate=45]
\everymath=\expandafter{\the\everymath\mathrm}
%
\draw[thick]    (0,0) coordinate (A)    to["$c'$"]   coordinate (c)
                (5,1) coordinate (B)    to["$a'$"]     coordinate (a)
                (2,3) coordinate (C)    to["$a'$"]     coordinate (b)
                cycle;
\path   pic[Angle, "$\beta^\prime$"]  {angle=C--B--A}
        pic[Angle, "$\gamma^\prime$"] {angle=A--C--B}
        pic[Angle, "$\alpha^\prime$"] {angle=B--A--C};
\path   (A) -- ($(A)!3mm!180:(a)$) node {A}
        (B) -- ($(B)!3mm!180:(b)$) node {B}
        (C) -- ($(C)!3mm!180:(c)$) node {C};
    \end{tikzpicture}
\end{document}

First example:

enter image description here

Second example: first one is rotated for 45 degrees

enter image description here

5
  • Oh yeas, the use of calc for the vertices labels is clever too, I should have thought about that, once the midway of each edge defined ;) +1 And of course, use of quotes for the automatic edge labeling is also a good choice. That makes your solution a serious improvement of mine, congrats.
    – SebGlav
    Feb 20 at 15:44
  • I do indeed like this answer slightly better, but not so much because of the use of calc or quotes, but because of the settings of some parameters at the beginning, which makes it easier for you to change them all if you need to adjust something. I'll elaborate on this when I have time (for now I'm in a hurry and I ended up doing it manually). Anyway, thanks to both of you.
    – Andyc
    Feb 20 at 19:53
  • Zarko's answer is probably more accurate and that's fine if you accept it. There's no competition in trying to help others.
    – SebGlav
    Feb 20 at 20:13
  • @Zarko I have used this and it's very good indeed. Just one more question: What is the use of rounded corners=5pt and inner sep=2pt in every edge quotes/.style?
    – Andyc
    Feb 27 at 9:42
  • You can omit rounded corners and see changes in image. If there are not, than this is just a clutter (I forgot to remove it from my experiments with code :-)). with inner sep=2pt is set distance between node content and node border. It can be even smaller, for example 1pt. You can also omit this option. but than the edge labels will be further away from edges.
    – Zarko
    Feb 27 at 10:05
5

Here's a way to do this, using calc for the edges labels and angles,quotes for the vertices labels (similar to what you used to draw the inner angles).

This should remain correctly placed with any rotation angle.

\documentclass[tikz,border=3.14mm]{standalone}

\usetikzlibrary{calc,angles,quotes}

\begin{document}
    \begin{tikzpicture}[rotate=0]
        \coordinate (A) at (0,0);
        \coordinate (B) at (5,2);
        \coordinate (C) at (3,5);
        
        \draw (A) -- (B) coordinate[midway] (C') -- (C) coordinate[midway] (A') -- (A) coordinate[midway] (B') -- cycle
            pic["$A$",angle radius=15pt] {angle=C--A--B}
            pic["$B$",angle radius=15pt] {angle=A--B--C}
            pic["$C$",angle radius=15pt] {angle=B--C--A};
        
        \node (lbl_a) at ($(A')!10pt!-90:(C)$) {a};
        \node (lbl_b) at ($(B')!10pt!-90:(A)$) {b};
        \node (lbl_c) at ($(C')!10pt!-90:(B)$) {c}; 
    \end{tikzpicture}
\end{document}

Rotate = 0

rotate=0

Rotate = -30

rotate=-30

Rotate = -60

rotate=-60

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.