Please help! Tikz rendering error I can't find

What I’m trying to do: Render a Venn diagram. It renders fine in Overleaf and looks like the image pasted below, but I must be making a noob mistake with TikZJax Obsidian. Could anyone help me figure out what I’m doing wrong please?

Things I have tried: I’ve tinkered, but I’m kinda new to this so I’m not sure where to start trying solutions! I have successfully rendered other codes (example at the bottom).

The code I’m trying to render:

\begin{tikzpicture}[scale=1.0]

% -- Node definitions (just positions here) --
\node (M) at (0,0) {};
\node (K) at (1.8,0) {};

% -- 1) Fill M entirely (light blue for example) --
\fill[blue!30] (M) circle (1.5cm);

% -- 2) Fill K entirely, overlapping everything including the intersection --
\fill[red!30] (K) circle (1.5cm);

% -- Finally, draw the outlines and labels for clarity --
\draw (M) circle(1.5cm) node[above left] {$M$};
\draw (K) circle(1.5cm) node[above right] {$K$};
\node at (0.9,0) {$B$};

\draw[dashed] (0.9,0) circle (3cm) 
    node[above, yshift=3 cm] {Soft Boundary}; % Adjust position with yshift

\end{tikzpicture}

The code that I’ve rendered successfully:

(This is a completely different image for a different topic, but it works fine so the Venn should be possible, there aren’t any other silly mistakes like forgetting to turn on TikZJaX haha.)

\begin{document}

\begin{tikzpicture}[line join = round, line cap = round]
\pgfmathsetmacro{\factor}{1/sqrt(2)};
\coordinate [label=right:C] (C) at (2,0,-2*\factor);
\coordinate [label=left:B] (B) at (-2,0,-2*\factor);
\coordinate [label=above:A] (A) at (0,2,2*\factor);
\coordinate [label=below:D] (D) at (0,-2,2*\factor);

\foreach \i in {A,B,C,D}
    \draw[dashed] (0,0)--(\i);
\draw[-, fill=red!30, opacity=1] (A)--(D)--(B)--cycle;
\draw[-, fill=blue!30, opacity=.5] (A) --(D)--(C)--cycle;
\draw[-, fill=purple!30, opacity=.5] (B)--(D)--(C)--cycle;
\end{tikzpicture}

\end{document}

Thank you!

~A

I don’t know tikz, but this looks a little suspicious. Which node is it referring to? Or what is B? If its the definition of B, then why don’t you use it anymore?

Hello holroy! Thanks for the help :slight_smile: This line places a ‘B’ in the overlapping area of the Venn diagram.

Just as an experiment I removed it and tried to re-render the code in Obsidian and it still doesn’t render. If I remove this in Overleaf, the B just disappears.

Adding \begin{document} and \end{document} around your code, I got this output:

image

So maybe just adding those was the:

2 Likes

IT WORKED! :smiley:

At first I nothing happened and I wrote a big reply. Then I found out the last problem by accident (because my preview on this website wouldn’t load properly either!):

This: \end{document}```
Needed to be this:

\end{document}
```

Thank you holroy! :white_heart:

2 Likes