5

The following code defines a MWE:

enter image description here

\documentclass[dvipsnames]{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \draw[dashed,Cerulean] (0,0)--(1,0)--(1,4);
    \draw[thick,OrangeRed] (0,0) -- (1,4);
    \draw[|-|] (1.3,4) -- (1.3,0) node[xshift=5ex,align=center,midway] {\scriptsize height (4)};
    \draw[|-|]  (0,-0.25) -- (1,-0.25) node[below,midway] {\scriptsize base (1)} ;
    \end{tikzpicture}
\end{document}

The issue I have is that the shape is not a closed one and the corners where the hypotenuse and the other two sides meet are obviously unpleasant. Is there a way to have a closed path with different decorations and colors as in my example? Of course, much consideration needs to be given to the smoothness of the vertices.

azetina
  • 28,884

1 Answers1

2

This is not the most beautiful solution, but perhaps it works for you. I'm using a clipping path.

\documentclass[dvipsnames]{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \draw[|-|] (1.3,4) -- (1.3,0) node[xshift=5ex,align=center,midway] {\scriptsize height (4)};
        \draw[|-|]  (0,-0.25) -- (1,-0.25) node[below,midway] {\scriptsize base (1)} ;
        \path[clip] (0,0) -| (1,4) -- cycle;
        \draw[very thick,dashed,Cerulean] (0,0) -- (1,0) (1,0) -- (1,4);%To see the vertice at (1,0)
        \draw[very thick,OrangeRed] (0,0) -- (1,4);
    \end{tikzpicture}
\end{document}

enter image description here

osjerick
  • 6,970