I have been dabbling with the **TikZ package** to create some diagrams relevant to a first year microeconomics course. The following diagram of an excise tax may be useful to others wishing to integrate similar diagrams into their LaTeX documents or Beamer presentations. To use, insert the following code anywhere you like within a .tex document (you must include `\usepackage{tikz}`

in your header):

#### INSERT INTO .TEX DOCUMENT

[sourcecode]

% TikZ code: An excise tax

\begin{tikzpicture}[domain=0:5,scale=1,thick]

\usetikzlibrary{calc} %allows coordinate calculations.

\usetikzlibrary{decorations.pathreplacing} %allows drawing curly braces.

% Define linear parameters for supply and demand

\def\dint{4.5} %Y-intercept for DEMAND.

\def\dslp{-0.5} %Slope for DEMAND.

\def\sint{1.2} %Y-intercept for SUPPLY.

\def\sslp{0.8} %Slope for SUPPLY.

\def\tax{1.5} %Excise (per-unit) tax

% Define Supply and Demand Lines as equations of parameters defined above.

\def\demand{\x,{\dslp*\x+\dint}}

\def\supply{\x,{\sslp*\x+\sint}}

\def\demandtwo{\x,{\dslp*\x+\dint+\dsh}}

\def\supplytwo{\x,{\sslp*\x+\sint+\ssh}}

% Define coordinates.

\coordinate (ints) at ({(\sint-\dint)/(\dslp-\sslp)},{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});

\coordinate (ep) at (0,{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});

\coordinate (eq) at ({(\sint-\dint)/(\dslp-\sslp)},0);

\coordinate (dint) at (0,{\dint});

\coordinate (sint) at (0,{\sint});

\coordinate (teq) at ({(\sint+\tax-\dint)/(\dslp-\sslp)},0); %quantity

\coordinate (tep) at (0,{(\sint+\tax-\dint)/(\dslp-\sslp)*\sslp+\sint+\tax}); %price

\coordinate (tint) at ({(\sint+\tax-\dint)/(\dslp-\sslp)},{(\sint+\tax-\dint)/(\dslp-\sslp)*\sslp+\sint+\tax}); %tax equilibrium

\coordinate (sep) at (0,{\sslp*(\sint+\tax-\dint)/(\dslp-\sslp)+\sint});

\coordinate (sen) at ({(\sint+\tax-\dint)/(\dslp-\sslp)},{\sslp*(\sint+\tax-\dint)/(\dslp-\sslp)+\sint});

% DEMAND

\draw[thick,color=blue] plot (\demand) node[right] {$P(q) = -\frac{1}{2}q+\frac{9}{2}$};

% SUPPLY

\draw[thick,color=purple] plot (\supply) node[right] {Supply};

% Draw axes, and dotted equilibrium lines.

\draw[->] (0,0) — (6.2,0) node[right] {$Q$};

\draw[->] (0,0) — (0,6.2) node[above] {$P$};

\draw[decorate,decoration={brace},thick] ($(sep)+(-0.8,0)$) — ($(tep)+(-0.8,0)$) node[midway,below=-8pt,xshift=-18pt] {tax};

\draw[dashed] (tint) — (teq) node[below] {$Q_T$};

\draw[dashed] (tint) — (tep) node[left] {$P_d$};

\draw[dashed] (sen) — (sep) node[left] {$P_s$};

\end{tikzpicture}

[/sourcecode]

The TikZ code snippet above is meant to be dropped into a .tex document and work without any further “tinkering”. Please let me know if this is not the case!

Thanks. I’ve just discovered Tikz and these code snippets are really helpful as I get more familiar with the package.

I’m having problems with the line:

\draw[decorate,decoration={brace},thick] ($(sep)+(-0.8,0)$) — ($(tep)+(-0.8,0)$) node[midway,below=-8pt,xshift=-18pt] {tax};

Which is returning the error:

! Package Tikz Error: You need to load a decoration library.

The rest works fine without the tax brace line.

Any suggestions?

Hi Jim – Have you included

`\usetikzlibrary{decorations}`

in the preamble of your .tex document?You may have to load a specific decorations (sub-)library for the particular decoration you are using – see this post at StackOverflow. That would mean adding something in your document preamble such as

`\usetikzlibrary{decorations.pathmorphing}`

. And, the last idea I have is that you may be using an older build of PGF/TIKZ. You can find and install the latest builds at http://www.texample.net/tikz/builds/ . Hope this helps. -KevinThanks Kevin.

After some trial and error I think I found the solution.

As you suggested I needed to load a specific decorations sub-library.

It turns out the one I needed was:

\usetikzlibrary{decorations.pathreplacing}

Can you suggest any easy way to identify to the appropriate decoration sub-library? In some cases, such as this one, it was non-obvious (to me at least).

I’m intrigued why you didn’t encounter this problem? Did you specify only:

\usepackage{tikz}

\usetikzlibrary{decorations}

in the preamble?

Jim, thanks for catching this. I did include

`\usepackage{tikz}`

and`\usetikzlibrary{decorations.pathreplacing}`

in my preamble. I have updated the code in this post to reflect that. As far as identifying which sub-libraries to use, I don’t have any suggestions right now. If I do find something in the future, I will post it here.