垂直线和水平线相交吗?

垂直线和水平线相交吗?

此来源存在问题:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\draw[thick,->] (-1,0) -- (5,0) node(xaxis)[below] {\footnotesize $x$};
\draw[thick,->] (0,-1) -- (0,6.5) node(yaxis)[left] {\footnotesize $y$};
\path [name path=line2] ( 0,4.5 ) -- +( 5,0 );
\path [name path=line1] ( 0,2 ) -- +( 3,0 );
\draw[red,very thick,name path=curve] (0.5,1) .. controls (1.5,3) and (4,2.5) .. (4.5,5.5);
\path [name intersections={of=curve and line2 , by=X}];
\path [name intersections={of=line1 and curve, by=Y}];
\draw (yaxis|-X)node[ left]{\footnotesize $f(b)$} -| ( xaxis-|X)node[below]{\footnotesize $b$};
\draw (yaxis|-Y)node[ left]{\footnotesize $f(a)$} -| ( xaxis-|Y)node[below]{\footnotesize $a$};
\end{tikzpicture}%

\end{document}

如何删除小线:在此处输入图片描述

答案1

坐标(yaxis |- X)由节点中心决定yaxis,而不是由其右(东)边界决定,如您所愿。因此,对于所有以此方式确定的坐标,您需要将其更改为yaxis.east并将更改为xaxis.north

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
    \begin{tikzpicture}[font=\footnotesize]
\draw[thick,->] (-1,0) -- (5,0.0) node(xaxis)[below] {$x$};
\draw[thick,->] (0,-1) -- (0,6.5) node(yaxis)[left]  {$y$};
%
\draw[red,very thick,name path=curve] (0.5,1) .. controls (1.5,3) and (4,2.5) .. (4.5,5.5);
\path [name path=line2] (0,4.5) -- +(5,0);
\path [name path=line1] (0,2.0) -- +(3,0);
%
\path [name intersections={of=curve and line2 , by=X}];
\path [name intersections={of=line1 and curve, by=Y}];
%
\draw (yaxis.east |- X) node[left] {$f(b)$} -| (xaxis.north -| X)node[below]{$b$};
\draw (yaxis.east |- Y) node[left] {$f(a)$} -| (xaxis.north -| Y)node[below]{$a$};
    \end{tikzpicture}%
\end{document}

如您所见,我稍微修改了您的 MWE。

相关内容