1

I have a simple question. I am creating a schematic drawing in TikZ without using the axis feature where I need to shade a region between a L-shape (part of a rectangle) and a spline generated using control points. However, the tikzfillbetween command completely ignores the control points of the spline and treats it as a straight line between its endpoints. Please let me know how I can fix it. I have included my code and attached the (undesired) output.

Thanks in advance for your help.

Sid

\documentclass[10pt]{article}
\usepackage[paperwidth=8.5in,paperheight=11.0in, left=1.25in,right=1.25in,top=1.25in,bottom=1.25in, includefoot]{geometry}               
\usepackage{graphicx}
\usepackage{float}
\usepackage{pgfplots}enter image description here
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{figure}[H]
\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}
\draw[thick, black, name path=rect1] (0,4) -- (0,0) -- (4,0);
\draw[thick, black, name path=rect2] (4,0) -- (12,0) -- (12,4) -- (0,4);
\draw[thick, black, name path=topo] (0,4) .. controls (2.5,2.5) and (1.5,0)  .. (4,0);
\tikzfillbetween[of=rect1 and topo]{fill=gray,fill opacity=0.5,pattern=north east lines};
\end{tikzpicture}
\end{minipage} 
\end{figure} 

\end{document}

Undesired Output

1

Try the following:

\documentclass{article}
\usepackage[paperwidth=8.5in, paperheight=11.0in, 
            margin=1.25in, 
            includefoot]{geometry}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
    \begin{figure}
\centering
\begin{tikzpicture}
\draw[thick] (0,0) rectangle ++ (12,4);
\draw[thick, fill opacity=0.5,
      pattern=north east lines] (0,0) -- (0,4) .. controls (2.5,2.5) and (1.5,0)  .. (4,0);
\end{tikzpicture}
    \end{figure}
\end{document}

From Your preamble I delete all not relevant packages and libraries for this solution. As you can see, it not use \tikzfillbetween but simple fill.

enter image description here

With use of the \tikzfillbetween library you need to give names only to two paths, for example A which is on bottom of rectangle, and B which is named of curve:

\documentclass{article}
\usepackage[paperwidth=8.5in, paperheight=11.0in, 
            margin=1.25in, 
            includefoot]{geometry}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{document}
    \begin{figure}
\centering
\begin{tikzpicture}
\draw[thick] (0,0) rectangle ++ (12,4);
\path[name path=A] (0,0) -- (12,0);  % <---
\draw[thick, name path=B] (0,4) .. controls (2.5,2.5) and (1.5,0) .. (4,0); % <---
\tikzfillbetween[of=A and B] {fill=gray, fill opacity=0.5, pattern=north east lines};
\end{tikzpicture}
    \end{figure}
\end{document}

result is the same as before.

  • Thank you so much! – Sid Jul 19 at 3:13

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.