3

I want to change the tip of a line in latex. For example consider the following MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[yscale=5,thick,domain=-2:2,smooth,variable=\x] plot ({\x},{exp(-\x*\x)/sqrt(2*pi)});
\draw[ultra thick] (1.3,0)--(1.3,{5*exp(-1.69)/sqrt(2*pi)});
\end{tikzpicture}
\end{center}
\end{document}

In the output of the above lines of code, the upper tip of the straight line drawn doesn't completely match with the bell-shaped curve. This straight line is like a filled rectangle, whereas I want it to be like a filled trapezium, when zoomed. (Additionally, I would also be very happy to see any suggestion on how to draw normal density function easily, instead of specifying that manually.)

2

You can use clip. Note also that it appears worthwhile to declare a function here.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=5*exp(-\x*\x)/sqrt(2*pi);}]
\begin{scope}[thick]
 \draw[clip] plot [domain=-2:2,smooth,variable=\x] ({\x},{f(\x)});
 \draw[ultra thick] (1.3,0)--(1.3,{f(1.3)+0.1});
\end{scope} 
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

enter image description here

Everything inside the scope will be clipped.

Alternatively you can just use a plot.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=5*exp(-\x*\x)/sqrt(2*pi);}]
 \draw[thick] plot [domain=-2:2,smooth,variable=\x] ({\x},{f(\x)});
 \fill plot[variable=\x,domain=-8:8] 
 ({1.3cm+0.1*\x*1pt},{f(1.3+0.1*\x*1pt/1cm)*1cm})
 |- ({1.3cm-0.8pt},0);
\end{tikzpicture}
\end{center}
\end{document}

As for the extended comments below this post: clip clips everything that comes after it in the path. So it seems to me that you might want

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=5*exp(-\x*\x)/sqrt(2*pi);}]
\begin{scope}[thick]
 \draw (-2.5,0)--(4.5,0);
 \draw plot [domain=-2:2,smooth,variable=\x] ({\x},{f(\x)});
 \clip plot [domain=-2:2,smooth,variable=\x] ({\x},{f(\x)}) -- (4.5,0) -- (-2.5,0);
 \draw[ultra thick] (1.3,0)--(1.3,{f(1.3)+0.1});
\end{scope} 
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

14
  • 1
    @Martund Could you please explain what you mean by "not working"? Did you use the code as is? What problems do you have? As for the fill, this really just fills the area under the plot that goes from x=1.3cm-0.8pt to 1.3cm+0.8pt since ultra thick sets the line width to 1.6pt. – user194703 May 8 '20 at 15:08
  • 1
    @Martund You need to put the clip and the ultra thick line in a scope. – user194703 May 9 '20 at 16:13
  • 1
    @Martund If you start a scope and put a \clip command in this scope, only stuff that is in the scope and after the \clip command will be clipped. You seem to have a specific use case and ask questions related to that. It would be much easier to answer these if I knew how the use case looks like explicitly. – user194703 May 9 '20 at 17:09
  • 1
    @Martund As I said, everything after the clip will be clipped, so \begin{scope}[thick] \draw (-2.5,0)--(4.5,0); \clip[draw] plot[domain=-2:2,smooth,variable=\x] ({\x},{f(\x)}); \draw[ultra thick] (1.3,0)--(1.3,{5*exp(-1.69)/sqrt(2*pi)}); \end{scope}, i.e. put \draw (-2.5,0)--(4.5,0); before the path that has the clip. – user194703 May 9 '20 at 17:24
  • 1
    @Martund I added an example at the end of the post. Given the explicit codes I think to understand better what you want. – user194703 May 9 '20 at 17:44

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.