垂直線和水平線的交點?

垂直線和水平線的交點?

這個原始碼有問題:

\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.eastxaxis.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。

相關內容