I tried to write a simple tikzcode:



   [scale=3,line cap=round,
    % Styles
      important line/.style={very thick},
      information text/.style={rounded corners,fill=red!10,inner sep=1ex}]
    \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);
  % 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);


which produce figure: function

First I'd like to ask how to color the text which I entered with the commands

  • \coordinate [label=left:$D$] (D) at (0.3,0.5); % letter D
  • \coordinate [label=right:$C$] (C) at (1.2,1.2); % letter C

I would also like to ask whether anyone would help improve my code. I am a beginner, so it will probably be quite inefficient.


1 Answer 1


To answer the specific question:

A label can be coloured with the same syntax you used for shifting the A and B labels, only by writing the colour name in the brackets, e.g.

\coordinate [label={[blue]left:$D$}] (D) at (0.3,0.5);

If you want to set the colour of all labels in a picture, use the every label style, e.g.

\begin{tikzpicture}[every label/.style={color=blue}]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .