Banner image for Wesley T. Honeycutt's website.  His contact emails are listed in the image.  Click to return home

LaTeX: Drawing MOSFET in TikZ - Labels and Animation

Continuing from last week's post, this week we will be adding labels to our MOSFET in TikZ and adding slide animations with Beamer. As a reminder, last week we drew our image of a MOSFET in Tikz before adding colors. The colors we added were based on the materials used in each part of the n-type MOSFET. Now let's add some labels to make sure that anyone we present this image to can understand what is going in.

Centered Labels

Now we take the code from last week and add "nodes" to certain of our shapes. We tell these nodes to have certain text and compile. [code lang="latex"]\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{patterns} \title{\LaTeX~Surface Science and Electronics} \author{Wesley T. Honeycutt} \date{\today} \newcommand{\metalone}{[pattern= horizontal lines, pattern color=blue]} \newcommand{\metaltwo}{[pattern= vertical lines, pattern color=purple]} \newcommand{\poly}{[pattern= grid, pattern color=red]} \newcommand{\pdiff}{[pattern= north east lines, pattern color=orange]} \newcommand{\ndiff}{[pattern= north west lines, pattern color=green]} \newcommand{\pwell}{[pattern= crosshatch dots, pattern color=orange]} \newcommand{\nwell}{[pattern= crosshatch dots, pattern color=green]} \newcommand{\oxide}{[pattern = bricks, pattern color = olive]} \newcommand{\silicon}{[fill = white]} \newcommand{\metalthree}{[fill = teal]} \begin{document} \frame{\titlepage} \frame{\frametitle{MOSFET} % General n-type mosfet \begin{tikzpicture} \draw \pdiff (0,.25) -- (0,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) -- (11,3) -- (11,.25) -- (0,.25) node {p-type}; \draw \metalthree (0,0) rectangle (11,.25) node {Si Substrate}; \draw \oxide (4,3) rectangle (7,4) node {oxide}; \draw \metalone (4,4) rectangle (7,4.5); \draw \ndiff (4.25,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) node {n-type}; \draw \ndiff (10,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) node {n-type}; \draw \metalone (1.25,3) rectangle (3,3.5); \draw \metalone (8,3) rectangle (9.75,3.5); \end{tikzpicture} } \end{document} [/code] This gives us the following image with ill-placed text:
Ill-placed text on our MOSFET

The text looks odd because the node location in TikZ defaults to the last point in the drawing. We can tell it to place the node in a certain location with respect to this anchor point. Additionally, I might want to change some other properties such as text color for my labels. This can all be done in brackets after declaring the node. Now my code becomes: [code lang="latex"]\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{patterns} \title{\LaTeX~Surface Science and Electronics} \author{Wesley T. Honeycutt} \date{\today} \newcommand{\metalone}{[pattern= horizontal lines, pattern color=blue]} \newcommand{\metaltwo}{[pattern= vertical lines, pattern color=purple]} \newcommand{\poly}{[pattern= grid, pattern color=red]} \newcommand{\pdiff}{[pattern= north east lines, pattern color=orange]} \newcommand{\ndiff}{[pattern= north west lines, pattern color=green]} \newcommand{\pwell}{[pattern= crosshatch dots, pattern color=orange]} \newcommand{\nwell}{[pattern= crosshatch dots, pattern color=green]} \newcommand{\oxide}{[pattern = bricks, pattern color = olive]} \newcommand{\silicon}{[fill = white]} \newcommand{\metalthree}{[fill = teal]} \begin{document} \frame{\titlepage} \frame{\frametitle{MOSFET} % General n-type mosfet \begin{tikzpicture} \draw \pdiff (0,.25) -- (0,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) -- (11,3) -- (11,.25) -- (0,.25) node [midway,above] {p doped Si}; \draw \metalthree (0,0) rectangle (11,.25) node [midway, color=white] {Si Substrate}; \draw \oxide (4,3) rectangle (7,4) node [pos=.5,font=\bf\Large] {oxide}; \draw \metalone (4,4) rectangle (7,4.5); \draw \ndiff (4.25,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) node at (2.625,2.5) [align=center] {n-type}; \draw \ndiff (10,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) node at (8.375,2.5) [align=center] {n-type}; \draw \metalone (1.25,3) rectangle (3,3.5); \draw \metalone (8,3) rectangle (9.75,3.5); \end{tikzpicture} } \end{document} [/code] In this case, I have added some alignment options for different locations. The image ends up looking like this:
Placement and Style

Labels on Arrows

I've decided that I want to label the metal connections on our MOSFET, but I don't want to place the text directly over the shape. Instead, I want to tell TikZ to draw little arrows pointing to what is labeled. This is easy. We just draw a line, which we tell to have an arrowhead, from a point to another point. At the first point, we tell it to have a label. I have used: [code lang="latex"]\draw [->] (1,5) node [above] {Source} -- (2.125,3.5); \draw [->] (10,5) node [above] {Drain} -- (8.975,3.5); \draw [->] (5.5,5) node [above] {Gate} -- (5.5,4.5); [/code] Which when implemented, looks like this:
Example implementaiton of TikZ points

Animation with Beamer

Did you know that the same person that wrote TikZ wrote Beamer, the LaTeX slideshow creator? It's true. This makes things quite convenient, as the author has designed it such that it is easy to integrate slide animations into your TikZ code. For the final part of our MOSFET in TikZ, I'm going to add some animation. I want to make it obvious to the viewer how my MOSFET works going from the off state to saturation mode. I will do this by adding nodes to present the voltage relationship of each state on the screen, then pop up an image of the electron rich areas of the MOSFET. This is very easy to do with \only. Check out the final code below: [code lang="latex"]\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{patterns} \title{\LaTeX~Surface Science and Electronics} \author{Wesley T. Honeycutt} \date{\today} \newcommand{\metalone}{[pattern= horizontal lines, pattern color=blue]} \newcommand{\metaltwo}{[pattern= vertical lines, pattern color=purple]} \newcommand{\poly}{[pattern= grid, pattern color=red]} \newcommand{\pdiff}{[pattern= north east lines, pattern color=orange]} \newcommand{\ndiff}{[pattern= north west lines, pattern color=green]} \newcommand{\pwell}{[pattern= crosshatch dots, pattern color=orange]} \newcommand{\nwell}{[pattern= crosshatch dots, pattern color=green]} \newcommand{\oxide}{[pattern = bricks, pattern color = olive]} \newcommand{\silicon}{[fill = white]} \newcommand{\metalthree}{[fill = teal]} \begin{document} \frame{\titlepage} \frame{\frametitle{MOSFET} % General n-type mosfet \begin{tikzpicture} \draw \pdiff (0,.25) -- (0,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) -- (11,3) -- (11,.25) -- (0,.25) node [midway,above] {p doped Si}; \draw \metalthree (0,0) rectangle (11,.25) node [midway, color=white] {Si Substrate}; \draw \oxide (4,3) rectangle (7,4) node [pos=.5,font=\bf\Large] {oxide}; \draw \metalone (4,4) rectangle (7,4.5); \draw \ndiff (4.25,3) -- (1,3) -- (1,2.5) to [out=270,in=180] (1.5,2) -- (3.75,2) to [out=0,in=270] (4.25,2.5) -- (4.25,3) node at (2.625,2.5) [align=center] {n-type}; \draw \ndiff (10,3) -- (6.75,3) -- (6.75,2.5) to [out=270,in=180] (7.25,2) -- (9.5,2) to [out=0,in=270] (10,2.5) -- (10,3) node at (8.375,2.5) [align=center] {n-type}; \draw \metalone (1.25,3) rectangle (3,3.5); \draw \metalone (8,3) rectangle (9.75,3.5); \draw [->] (1,5) node [above] {Source} -- (2.125,3.5); \draw [->] (10,5) node [above] {Drain} -- (8.975,3.5); \draw [->] (5.5,5) node [above] {Gate} -- (5.5,4.5); \only<1> {\node at (5.5,-.5) [align=center] {$V_{GS} < V_{threshold}$};} \only<2-3> {\node at (5.5,-.5) [align=center] {$V_{GS} \geq V_{threshold}$}; \node at (5.5,-1) [align=center] {$V_{DS} < V_{GS} - V_{threshold}$}; } \only<3> {\draw [fill=white] (4.25,3) rectangle (6.75,2.5); \draw \ndiff (4.25,3) rectangle (6.75,2.5); } \only<4-5> {\node at (5.5,-.5) [align=center] {$V_{GS} \geq V_{threshold}$}; \node at (5.5,-1) [align=center] {$V_{DS} = V_{GS} - V_{threshold}$}; } \only<5> {\draw [fill=orange,orange] (4.25,3) rectangle (6.75,2.5); \draw [fill=white] (4.25,3) -- (4.25,2.65) -- (6.75,3) -- (4.75,3); \draw \ndiff (4.25,3) -- (4.25,2.65) -- (6.75,3) -- (4.75,3); } \only<6-7> {\node at (5.5,-.5) [align=center] {$V_{GS} \geq V_{threshold}$}; \node at (5.5,-1) [align=center] {$V_{DS} > V_{GS} - V_{threshold}$}; } \only<7> {\draw [fill=orange,orange] (4.25,3) rectangle (6.75,2.5); \draw [fill=white] (4.25,3) -- (4.25,2.85) -- (6.75,3) -- (4.75,3); \draw \ndiff (4.25,3) -- (4.25,2.85) -- (6.75,3) -- (4.75,3); } \end{tikzpicture} } \end{document} [/code] Each time I add an \only, I put slide numbers in pointed braces. The code between the curly braces will "only" show up on the slides listed in the pointed braces. The result of this code is shown in the following gif: Animated MOSFET in TikZ and Beamer showing operation modes

Wrap Up

I know that creating a MOSFET in TikZ is a bit specific. Still, I hope that this little tutorial gives everyone a feel for how to take make nice scale-able images in LaTeX using TikZ.
URL slug: latex-mosfet-tikz-labels-animation
Originally published: 2017-07-19 13:00:32
Content last regnerated: 2024-09-22 16:59:04