# How to add a title to tikzpicture + smoother function lines

I know that my first question from the title has been asked several times, but when I try to apply the solutions from other the questions, they don't work.

What I want to achieve, is to add a title to these two functions:

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[thick,font=\footnotesize]
\fill [blue!10] (0,0) -- (0.55,0) -- (0.55,0.55) -- (0,0.55) -- cycle;
\draw[->] (0,0) -- (5,0) node[right] {$Quantity$};
\draw[->] (0,0) -- (0,5) node[above] {$Price$};
\coordinate (p1) at (0.55,0.55);
\draw[color=blue,domain=0.067:4.5] plot (\x,{(0.3)/(\x)});
\draw[dotted] (p1) -- (0.55,0) node[below] {$Q^*$};
\draw[dotted] (p1) -- (0,0.55) node[left] {$P^*$};
\fill[blue] (p1) circle (2pt);
\end{tikzpicture}
\begin{tikzpicture}[thick,font=\footnotesize]
\fill [blue!10] (0,0) -- (1,0) -- (1,2) -- (0,2) -- cycle;
\draw[->] (0,0) -- (5,0) node[right] {$Quantity$};
\draw[->] (0,0) -- (0,5) node[above] {$Price$};
\coordinate (p1) at (1,2);
\draw[color=blue,domain=0:2] plot (\x,{(2-\x)*2});
\draw[dotted] (p1) -- (1,0) node[below] {$Q^*$};
\draw[dotted] (p1) -- (0,2) node[left] {$P^*$};
\fill[blue] (p1) circle (2pt);
\end{tikzpicture}
\caption{Optimal side A and B pricing under marginal costs, based on XXX}
\end{figure}
\end{document}


Most solutions state that one should add \node + label to each of the tikzpictures, but I'm getting critical errors whenever I try to incorporate this. So my questions would be:

1) How can I add a title above each picture?

2) Regarding the convex curve in the left picture: there is an "edge" on the blue function - Any idea how this can be fixed?

Thank you!

• your example produces ! LaTeX Error: Unknown float option H'.and if I remove the H Runaway argument? {Optimal side A and B pricing under marginal costs, based on \end {fi\ETC. ! File ended while scanning use of \@xdblarg. – David Carlisle Nov 11 '16 at 18:15
• Thank you, I corrected this in the original code and works now. – Malganas Nov 11 '16 at 18:50

One way would be to place a node relative to the current bounding box, as in the example below. You could of course use explicit coordinates as well, e.g. \node at (2.5,5.2) {Some title};.

For the plot, add samples=100 or something like that. The default number of samples is 25, more samples gives smoother curves (and longer compile times). And an unrelated note, don't write Price and Quantity in math mode.

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[thick,font=\footnotesize]
\fill [blue!10] (0,0) -- (0.55,0) -- (0.55,0.55) -- (0,0.55) -- cycle;
\draw[->] (0,0) -- (5,0) node[right] {Quantity};
\draw[->] (0,0) -- (0,5) node[above] {Price};
\coordinate (p1) at (0.55,0.55);
\draw[color=blue,domain=0.067:4.5,samples=100] plot (\x,{(0.3)/(\x)});
\draw[dotted] (p1) -- (0.55,0) node[below] {$Q^*$};
\draw[dotted] (p1) -- (0,0.55) node[left] {$P^*$};
\fill[blue] (p1) circle (2pt);
\node[above,font=\large\bfseries] at (current bounding box.north) {Some title};
\end{tikzpicture}%
\begin{tikzpicture}[thick,font=\footnotesize]
\fill [blue!10] (0,0) -- (1,0) -- (1,2) -- (0,2) -- cycle;
\draw[->] (0,0) -- (5,0) node[right] {Quantity};
\draw[->] (0,0) -- (0,5) node[above] {Price};
\coordinate (p1) at (1,2);
\draw[color=blue,domain=0:2] plot (\x,{(2-\x)*2});
\draw[dotted] (p1) -- (1,0) node[below] {$Q^*$};
\draw[dotted] (p1) -- (0,2) node[left] {$P^*$};
\fill[blue] (p1) circle (2pt);
\node[above,font=\large\bfseries] at (current bounding box.north) {Some other title};
\end{tikzpicture}
\caption{Optimal side A and B pricing under marginal costs, based on}
\end{figure}
\end{document}

• Why your previous efforts to place a node didn't work is impossible to say as you didn't tell us what you tried. – Torbjørn T. Nov 11 '16 at 18:23
• Thank you so much! Both solutions worked. What I tried to do comes from the following link and is \node[label=above:\textbf{Title}] – Malganas Nov 11 '16 at 18:37
• @Daniel Well, that's different, there the plot is an image that is placed inside a node, which is the only thing in the tikzpicture, and the title is a label for that node. If you did \node [label=above:title] {}; (you always have to have the node text in {}) the empty node would be placed at the default coordinate (0,0), and title would be placed right above it. But you draw other stuff, so you need to specify the coordinates for the node. – Torbjørn T. Nov 11 '16 at 18:42
• Nice. I have found the following useful in a related context: \node[above,font=\large\bfseries]at ($(current bounding box.north west)+(1,1)$) {Some title}; with \usetikzlibrary{calc}` – PatrickT Dec 1 '18 at 15:38