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.

I'd like to add text to the Penrose triangle (code below) and write
"London", "Paris", "Berlin" on the sides. How can I do that?

\begin{tikzpicture}[scale=1, line join=bevel]

% \a and \b are two macros defining characteristic
% dimensions of the Penrose triangle.       
\pgfmathsetmacro{\a}{1.8}
\pgfmathsetmacro{\b}{0.7}

\tikzset{%
  apply style/.code     = {\tikzset{#1}},
  triangle_edges/.style = {thick,draw=black}
}

\foreach \theta/\facestyle in {%
    0/{triangle_edges, fill = gray!50},
  120/{triangle_edges, fill = gray!25},
  240/{triangle_edges, fill = gray!90}%
}{
  \begin{scope}[rotate=\theta]
    \draw[apply style/.expand once=\facestyle]
      ({-sqrt(3)/2*\a},{-0.5*\a})                     --
      ++  (-\b,0)                                       --
        ({0.5*\b},{\a+3*sqrt(3)/2*\b})                -- % higher point 
        ({sqrt(3)/2*\a+2.5*\b},{-.5*\a-sqrt(3)/2*\b}) -- % rightmost point
      ++({-.5*\b},-{sqrt(3)/2*\b})                    -- % lower point
        ({0.5*\b},{\a+sqrt(3)/2*\b})                  --
      cycle;

    \end{scope}
  } 
 \end{tikzpicture}

Thanks, Marco

share|improve this question
1  
Please include your sources if you pickup the code from somewhere. It's not for legal nonsense but just for being a good sport. tex.stackexchange.com/a/150218/3235 –  percusse Aug 31 at 15:07

2 Answers 2

Penrose's travels

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning,decorations.text}

\begin{document}

\begin{tikzpicture}[scale=1, line join=bevel]

% \a and \b are two macros defining characteristic
% dimensions of the Penrose triangle.
\pgfmathsetmacro{\a}{1.8}
\pgfmathsetmacro{\b}{0.7}

\tikzset{%
  apply style/.code     = {\tikzset{#1}},
  triangle_edges/.style = {thick,draw=black}
}

\foreach \theta/\facestyle/\city in {%
    0/{triangle_edges, fill = gray!50}/London,
  120/{triangle_edges, fill = gray!25}/Paris,
  240/{triangle_edges, fill = gray!90}/Berlin%
}{
  \begin{scope}[rotate=\theta]
    \draw[apply style/.expand once=\facestyle]
      ({-sqrt(3)/2*\a},{-0.5*\a})
      -- ++  (-\b,0) coordinate (\city1)
      -- ({0.5*\b},{\a+3*sqrt(3)/2*\b}) coordinate (\city2) % higher point
      --  ({sqrt(3)/2*\a+2.5*\b},{-.5*\a-sqrt(3)/2*\b}) coordinate (\city3)% rightmost point
      -- ++({-.5*\b},-{sqrt(3)/2*\b}) coordinate (\city4) % lower point
      --  ({0.5*\b},{\a+sqrt(3)/2*\b}) coordinate (\city5)
      --  cycle
      ;
  \end{scope}
}
  \path [decorate, decoration={text along path, text={Paris}, text align=center, text color=darkgray}]
    ($(Paris5) - (1/3*\b,0)$) -- ($(Paris4)!1/3!(Paris3)$);
  \path [decorate, decoration={text along path, text={London}, text align=center, text color=darkgray}]
    ($(London5) + (1/3*\b,0)$) -- ($(London3) - (2/3*\b,0)$);
  \path [decorate, decoration={text along path, text={Berlin}, text align=center, text color=white}]
    ($(Berlin3)!1/3!(Berlin3 |- Berlin4)$) -- ($(Berlin5)!2/3!(Berlin3 -| Berlin5)$);
\end{tikzpicture}

\end{document}
share|improve this answer

EDIT: As per requested by the OP, the labels are now rotated with each face.

Try this:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}

\begin{tikzpicture}[scale=1, line join=bevel]

% \a and \b are two macros defining characteristic
% dimensions of the Penrose triangle.       
\pgfmathsetmacro{\a}{1.8}
\pgfmathsetmacro{\b}{0.7}

\tikzset{%
  apply style/.code     = {\tikzset{#1}},
  triangle_edges/.style = {thick,draw=black}
}

\foreach \theta/\facestyle/\city/\al\/\ang in {%
    0/{triangle_edges, fill = gray!50}/Paris/below/-60,
  120/{triangle_edges, fill = gray!25}/Berlin/below/60,
  240/{triangle_edges, fill = gray!90}/London/above/0}
  {
  \begin{scope}[rotate=\theta]
    \draw[apply style/.expand once=\facestyle]
      ({-sqrt(3)/2*\a},{-0.5*\a})                   --
      ++  (-\b,0)                                   --
        ({0.5*\b},{\a+3*sqrt(3)/2*\b})                --node[\al,rotate=\ang]{\city} % higher point 
        ({sqrt(3)/2*\a+2.5*\b},{-.5*\a-sqrt(3)/2*\b}) -- % rightmost point
      ++({-.5*\b},-{sqrt(3)/2*\b})                    -- % lower point
        ({0.5*\b},{\a+sqrt(3)/2*\b})                  --
      cycle;
    \end{scope}
  } 
 \end{tikzpicture}
\end{document}

The triangle now looks like this:

enter image description here

share|improve this answer
    
Thanks, but I want the words to span on the sides of the triangle. –  Marco Aug 31 at 13:20
    
@Marco: if you mean you want the words "aligned" with the sides, try [midway,\al,sloped] –  Pier Paolo Aug 31 at 14:44
    
Well, I want them to be aligned but "inside" the lines of the triangle. Don't know how to explain this in a better way. For instance, the word London should be in the dark gray area of the lower side of the triangle. –  Marco Aug 31 at 15:39
    
@Marco See my updated answer. –  AboAmmar Aug 31 at 19:25

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.