Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried to write a simple 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}

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.

Thanks

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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}]
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.