我尝试编写一个简单的 tikzcode:
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
[scale=3,line cap=round,
% Styles
axes/.style=,
important line/.style={very thick},
information text/.style={rounded corners,fill=red!10,inner sep=1ex}]
\begin{scope}[axes]
\draw[->] (-0.2, 0) -- (1.5, 0) node[right] {$x$} coordinate(x axis);
\draw[->] (0, -0.2) -- (0, 1.5) node[left] {$y$} coordinate(y axis);
\end{scope}
% my function
\draw[very thick,red](1.5,1.5) node[left=1pt,fill=white]{$y=f(x)$};
\coordinate [label=left:$D$] (D) at (0.3,0.5);
\coordinate [label=right:$C$] (C) at (1.2,1.2);
\draw[name path=func] (D) .. controls (1.0,0.5) and (0.5,1.2) .. (C);
% horizontal line
\draw[name path=my_line, gray, dotted] (0.75,0) node[below, red]{$c$} -- (0.75,0.9);
% intersection between vertical line and my function
\fill[red, opacity=0.5, name intersections={of=func and my_line, by={intersect}}]
(intersect) circle (1pt);
% x-axis labels
\draw[gray, dotted, text = red] (D) -- +(0,-0.5)
node [label={[xshift=-0.2cm, yshift=0.5mm]$A$},below] (A) {$a$};
\draw[gray, dotted, text=red] (C) -- +(0,-1.2)
node [label={[xshift=0.2cm, yshift=0.5mm]$B$},below] (B) {$b$};
\draw[red](-0.05,-0.08) node[left=1pt,fill=white]{$0$};
% y-axis labels
\draw[gray, dotted] let \p1=(D), \p2=(intersect), \p3=(C) in (\x1,\y2)
-- +(-\x1,0) node[left, red]{$f(c)$}
-- (\x1,\y2) node[above, red] (F) {$F$}
-- (\x3,\y2) node[right, red]{$E$};
% dotted line between F and D
\draw[gray, dotted] (F) -- (D);
\end{tikzpicture}
\end{document}
产生如下图形:
首先我想问一下如何为使用命令输入的文本着色
\coordinate [label=left:$D$] (D) at (0.3,0.5); % letter D
\coordinate [label=right:$C$] (C) at (1.2,1.2); % letter C
我还想问一下是否有人愿意帮助改进我的代码。我是初学者,所以效率可能很低。
谢谢
答案1
回答具体问题:
标签可以使用与shift
A 和 B 标签相同的语法来着色,只需在括号中写出颜色名称即可,例如
\coordinate [label={[blue]left:$D$}] (D) at (0.3,0.5);
如果你想设置颜色全部图片中的标签,使用every label
样式,例如
\begin{tikzpicture}[every label/.style={color=blue}]
...