1

Consider the following TIKZ code, producing 3 highlighted green vertices.

\documentclass{standalone}
\usepackage{tikz}

\tikzstyle{mycircle}=[draw, circle, minimum height=2.5mm]
\tikzstyle{mygreen}=[draw=green!80!black,fill=green!80!black!20!white]
\usetikzlibrary{backgrounds}

\begin{document}
    \begin{tikzpicture}[transform shape]
      \draw (4, 0) node[mycircle, mygreen] (V0) {};
      \draw (6.5, 1) node[mycircle, mygreen] (V1) {};
      \draw (9.25, 0) node[mycircle, mygreen] (V2) {};
    \scoped[on background layer] \filldraw [red!50, opacity=0.2, line width=3em, line join=round] (V0.center) -- (V2.center) -- (V1.center) -- cycle;
    \end{tikzpicture}
\end{document}

The output of the code is presented here: An output of the tikz code Is there a way to make the red middle part of a highlighted area to be at the same colour as the rest of the picture while keeping it semi-transparent?

2
  • 1
    Triangle, which you see, is space not covered by your \filldraw instruction. Try to increase line width to 3em. – Zarko Jul 3 '20 at 10:01
  • Hi, thanks for the comment. Indeed the inner triangle disappeared, but there is still one more to erase. Please take a look at the updated question. – Bartosz Bednarczyk Jul 3 '20 at 10:15
2

Your question is not very clear to me.

For the its first version you can consider my comment or use the following solution:

documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds}
\tikzstyle{mycircle}=[draw, circle, minimum height=2.5mm]
\tikzstyle{mygreen}=[draw=green!80!black,fill=green!80!black!20!white]

\begin{document}
    \begin{tikzpicture}
\node (V=) [mycircle, mygreen] at (4, 0) (V0) {};
\node (V1) [mycircle, mygreen] at (6.5, 1) {};
\node (V2) [mycircle, mygreen] at (9.25, 0) {};
    \scoped[on background layer]
{
\draw[red!10, line width=2.5em, line join=round] (V0.center) -- (V2.center) -- (V1.center) -- cycle;
\fill[red!25] (V0.center) -- (V2.center) -- (V1.center) -- cycle;
}
    \end{tikzpicture}
\end{document}

enter image description here

For the second version, if I understood you correctly, the solution can be:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds}

\begin{document}
    \begin{tikzpicture}[
mycircle/.style = {draw, circle, minimum size=2.5mm}
 mygreen/.style = {draw=green!80!black,fill=green!80!black!20!white}   
                        ]
\node (V=) [mycircle, mygreen] at (4, 0) (V0) {};
\node (V1) [mycircle, mygreen] at (6.5, 1) {};
\node (V2) [mycircle, mygreen] at (9.25, 0) {};
    \scoped[on background layer]
\filldraw[red!25, line width=2.5em, line join=round] (V0.center) -- (V2.center) -- (V1.center) -- cycle;
    \end{tikzpicture}
\end{document}

enter image description here

Note: function of opacity is to make fill (or line) transparent, i.e. that the drawing behind it is visible. Due to this in your example part of fill, which color area between zero width lines between nodes, cover inner half part of real line. Consequently, covered part of line is visible through the fill.

To have line and fill the same color, the color of the fill should not be transparent. To have fill more brighter, change the fill color, for example from red!25 to red!0.

Addendum (off topic): For exercise, how to make code for above MWE shorter:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
    \begin{tikzpicture}[
mycircle/.style args = {#1/#2}{circle,
                        draw=#1, semithick, fill=#2,
                        minimum size=2.5mm},
  mycircle/.default = green!80!black/green!80!black!20!white
                        ]
\begin{scope}[nodes=mycircle]
\filldraw[red!10, line width=5mm, line join=round]
    (0.00,0) node {} --
    (2.50,1) node {} --
    (5.25,0) node {} -- cycle;
\end{scope}
    \end{tikzpicture}
\end{document}

Result is the same as before.

4
  • The section version would be the correct one. However, as far as I see, you basically removed opacity option and now the colour of the whole picture is more visible, while I wanted it to be more transparent. – Bartosz Bednarczyk Jul 3 '20 at 10:48
  • 1
    @BartoszBednarczyk, what you mean with "transparent"? As I understood you, you not liked that fill is transparent, i.e. that through it is visible lines. You can change fill color, for example to red!10 ... – Zarko Jul 3 '20 at 11:55
  • I see, it works perfectly now. I was not aware that !10 works like this :) Thanks a lot for help! – Bartosz Bednarczyk Jul 3 '20 at 12:07
  • @BartoszBednarczyk, see edit in answer. – Zarko Jul 3 '20 at 12:07

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.