I'm trying to fill an area between two dotted lines. I tried a lot of options, but none of them seem to work.
I labeled the areas I need with the specific colors to fill. My current code is:
\documentclass[10pt,a4paper,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[centering,includeheadfoot,top=25mm, left=40mm, right=25mm, bottom=30mm]{geometry}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage{thmbox}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\fill[color=yellow] (0, 0) circle (2); % Sonne im Ursprung (0, 0)
\shade[right color=lightgray] (7.5, 0) circle (0.5); % Sonne im Ursprung (5, 0)
\shade[shading=ball, ball color=blue] (10, 0) circle (1); % Erde im Ursprung (10, 0)
\draw[dashed, color=red ,shorten >=-1.6cm,shorten <=-0cm,name path = A] (0, 2) --node[near start,sloped,above]{\textcolor{red}{Randstrahl}} (7.5, 0.5);
\draw[dashed, color=red ,shorten >=-3cm,shorten <=-0cm] (0, 2) -- (7.5, -0.5);
\draw[dashed, color=red ,shorten >=-1.6cm,shorten <=-0cm,name path = B] (0, -2) -- (7.5, -0.5);
\draw[dashed, color=red ,shorten >=-3cm,shorten <=-0cm] (0, -2) -- (7.5, 0.5);
\end{tikzpicture}
\end{document}
As mentioned, I tried a lot of options. So this is, more or less, a desperate attempt to solve my problem.
Best Answer
Welcome to TeX.SE! The reason why you cannot really fill the regions between the paths in your picture is that you used
shorten >=...
with some negative dimensions. Hence the paths are shorter than the dashed lines. I fixed that to make it work. And even though you could do that with the pgfplots libraryfillbetween
, this is not necessary here since you only have straight lines. And I usedbackgrounds
and slightly changed the order in which things get drawn in order not to overwrite your planets.Here is a version using tangents, as pioneered by esdd in this answer yet with a slightly different implementation/ Specifically, I use this answer to make the dashed lines tangent to both circles. There are other ways to achieve this, most notably those using the
tkz-euclide
library, see e.g. here. This solution finds the intersections without the intersection library, which works fine for straight lines.