Captioned images / figures in LaTeX


Download 1.76 Mb.
bet5/5
Sana04.04.2023
Hajmi1.76 Mb.
#1327896
1   2   3   4   5
Bog'liq
Grafika bilan ishlash

Text width


The final thing we should discuss is the text width. At the moment all our text fits nicely inside our shapes. However, if for example, we add some more text to process 2a, you'll see the shape just extends horizontally until the text fits:
\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a text text text text text text text text text text};

This now becomes a bit messy. To improve it we can specify the text width for these nodes by entering text width= followed by a length into our \tikzstyles:
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]

Open a TikZ flowchart example in Overleaf


The following example contains the code discussed above and can be opened directly in Overleaf. This code adds the option trapezium stretches=true to the node style definition, helping to ensure trapezium nodes are the same width.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{startstop} = [rectangle, rounded corners,


minimum width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=red!30]

\tikzstyle{io} = [trapezium,


trapezium stretches=true, % A later addition
trapezium left angle=70,
trapezium right angle=110,
minimum width=3cm,
minimum height=1cm, text centered,
draw=black, fill=blue!30]

\tikzstyle{process} = [rectangle,


minimum width=3cm,
minimum height=1cm,
text centered,
text width=3cm,
draw=black,
fill=orange!30]

\tikzstyle{decision} = [diamond,


minimum width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}

\begin{tikzpicture}[node distance=2cm]


\node (start) [startstop] {Start};


\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};

\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a


text text text text
text text text
text text text};

\node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b};


\node (out1) [io, below of=pro2a] {Output};
\node (stop) [startstop, below of=out1] {Stop};

\draw [arrow] (start) -- (in1);


\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) |- (pro1);
\draw [arrow] (pro2a) -- (out1);
\draw [arrow] (out1) -- (stop);

\end{tikzpicture}


\end{document}
 Open this example in Overleaf

This example produces the following output:



To get started we load up the circuitikz package.
\usepackage{circuitikz}
We don't need to load the TikZ package as well because it automatically gets loaded with circuitikz. To draw a diagram we use the circuitikz environment. We then fill the environment with a single \draw command ending in a semicolon.
\begin{circuitikz} \draw

;
\end{circuitikz}
The general format is then a pair of co-ordinates followed by a link and then the next pair of co-ordinates. You can then keep adding further links and co-ordinates like a chain. The link could simply be a line which is achieved using two dashes, or it could be an electrical component. To add a component on a line we use the keyword to followed by square brackets containing the name of the component. For example, we'll start at (0,0) and head towards (0,4) adding a battery in. We'll then add an ammeter in on the way to (4,4) followed by a simple line to (4,0). We'll complete the circuit by adding a lamp in on the way back (0,0):
\begin{circuitikz} \draw
(0,0) to[battery] (0,4)
to[ammeter] (4,4) -- (4,0)
to[lamp] (0,0)
;
\end{circuitikz}
This is what the diagram looks like compiled:

Now let's add a voltmeter in parallel to the lamp. To do this we want to branch off the bottom line part way along, then drop down, insert the meter, and then join back up with the bottom line before its end:
\begin{circuitikz} \draw
(0,0) to[battery] (0,4)
to[ammeter] (4,4) -- (4,0)
to[lamp] (0,0)
(0.5,0) -- (0.5,-2)
to[voltmeter] (3.5,-2) -- (3.5,0)
;
\end{circuitikz}

If we wanted to make the points where the lines join into proper terminals represented by circles, we could add *-* into the square brackets where we added the lamp in. This will add terminals in at the co-ordinates either side of the component. Therefore we need to shorten the lines either side of the lamp so that the terminals appear at our line joins, and then we need to fill in the gaps:
\begin{circuitikz} \draw
(0,0) to[battery] (0,4)
to[ammeter] (4,4) -- (4,0) -- (3.5,0)
to[lamp, *-*] (0.5,0) -- (0,0)
(0.5,0) -- (0.5,-2)
to[voltmeter] (3.5,-2) -- (3.5,0)
;
\end{circuitikz}

Next we'll add a capacitor in between the lamp and ammeter. We specify a capacitor with a capital C:
\begin{circuitikz} \draw
(0,0) to[battery] (0,4)
to[ammeter] (4,4)
to[C] (4,0) -- (3.5,0)
to[lamp, *-*] (0.5,0) -- (0,0)
(0.5,0) -- (0.5,-2)
to[voltmeter] (3.5,-2) -- (3.5,0)
;
\end{circuitikz}

Often we'll want to add labels to our diagrams to give the reader more information. To be able to include electrical units in our labels we need to add the siunitx option into the \usepackage command:
\usepackage[siunitx]{circuitikz}
We could add a label to the ammeter like this:
to[ammeter, l=2<\ampere>]

The l tells LaTeX we are adding a label. Notice that we put the unit commands in pointed brackets. As we're using SI units we could add an SI prefix in. We could also move the label to below the symbol by adding underscore immediately after the l:
to[ammeter, l_=2<\milli\ampere>]

As we are displaying current we could place the label next to an arrow on the line by changing the l to an i:
to[ammeter, i_=2<\milli\ampere>]

Let's add some labels in next to the capacitor and the voltmeter. With the capacitor we can just begin the label with an equals following the capital C:
\begin{circuitikz} \draw
(0,0) to[battery] (0,4)
to[ammeter, i_=2<\milli\ampere>] (4,4)
to[C=3<\farad>] (4,0) -- (3.5,0)
to[lamp, *-*] (0.5,0) -- (0,0)
(0.5,0) -- (0.5,-2)
to[voltmeter, l=3<\kilo\volt>] (3.5,-2) -- (3.5,0)
;
\end{circuitikz}

We could also change the colour of a component like this:
to[voltmeter, l=3<\kilo\volt>, color=red]

We can change the size of the diagram by adding a scaling factor in as an option at the end of the \begin command:
\begin{circuitikz}[scale=2] \draw

Notice that the components stay the same size but the spacing between everything changes.
Let's finish this post by looking at a selection of other components we could use:
\begin{circuitikz}
\draw
(0,0) to[R, o-o] (2,0)
(4,0) to[vR, o-o] (6,0)
(0,2) to[transmission line, o-o] (2,2)
(4,2) to[closing switch, o-o] (6,2)
(0,4) to[european current source, o-o] (2,4)
(4,4) to[european voltage source, o-o] (6,4)
(0,6) to[empty diode, o-o] (2,6)
(4,6) to[full led, o-o] (6,6)
(0,8) to[generic, o-o] (2,8)
(4,8) to[sinusoidal voltage source, o-o] (6,8)
;
\end{circuitikz}
These examples are all bipoles.

From the bottom left we have; a resistor, a variable resistor, a transmission line, a closing switch, a european current source, a european voltage source, an empty diode, a full led, a generic bipole and a sinusoidal voltage source.
Bipoles aren't the only type of component we can use. We can also add in monopoles, tripoles, double bipoles, logic gates and amplifiers. However we can't use the to keyword to add these in as we've done before, because they don't naturally fit on a single line. Instead we use node notation. For example, this is how we would display an antenna:
(0,0) node[antenna] {}

You can add text to the symbol using the curly brackets, but note that we still need to enter curly brackets even if we don't want to use them.
Here are some more examples:
(4,0) node[pmos] {}
(0,4) node[op amp] {}
(4,4) node[american or port] {}
(0,8) node[transformer] {}
(4,8) node[spdt] {}

To get started, we load up a the tikz package and the mindmap TikZ library. Next we open a tikzpicture environment:
\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\end{tikzpicture}
\end{document}
For our example we'll make a mind map to display the different video series' we've made. We'll start by making a tree diagram and then we'll format it into a real mind map. We start the tree with the title or central concept. This is added in using a node:
\node{ShareLaTeX Tutorial Videos}
We can then give this node children, which are themselves nodes which can also have their own children and so on. Let's add in four child nodes for the series titles. A child is inserted using the child keyword and then we specify a node in curly brackets. We close the original node statement with a semi colon just before the \end command. If we compile the code we can see our code has produced a sightly muddled tree diagram:
\begin{tikzpicture}

\node{ShareLaTeX Tutorial Videos}


child { node {Beginners Series}}
child { node {Thesis Series}}
child { node {Beamer Series}}
child { node {TikZ Series}}
;
\end{tikzpicture}

Let's add in the next layer of nodes and then we'll start formatting it to look more like a mind map:
\node{ShareLaTeX Tutorial Videos}
child { node {Beginners Series}
child { node {First Document}}
child { node {Sections and Paragraphs}}
child { node {Mathematics}}
child { node {Images}}
child { node {bibliography}}
child { node {Tables and Matrices}}
child { node {Longer Documents}}
}
child { node {Thesis Series}
child { node {Basic Structure}}
child { node {Page Layout}}
child { node {Figures, Subfigures and Tables}}
child { node {Biblatex}}
child { node {Title Page}}
}
child { node {Beamer Series}
child { node {Getting Started}}
child { node {Text, Pictures and Tables}}
child { node {Blocks, Code and Hyperlinks}}
child { node {Overlay Specifications}}
child { node {Themes and Handouts}}
}
child { node {TikZ Series}
child { node {Basic Drawing}}
child { node {Geogebra}}
child { node {Flow Charts}}
child { node {Circuit Diagrams}}
child { node {Mind Maps}}
};
To make the branches of our tree surround the central node we add the grow cyclic option into square brackets at the end of the begin command. We can also specify a text width and add the flush center alignment option in to tidy up our text:
\begin{tikzpicture}[grow cyclic, text width=2.7cm, align=flush center]
Next we'll specify styles for the different tree levels. Level 1 is defined as everything coming out of the main parent node while level 2 is everything coming out of the first generation of child nodes. So in our example, level 1 is everything coming out of the ShareLaTeX tutorial videos title and level 2 is everything coming out of our series titles. To specify the styles for these levels we write the name of the level followed by a forward slash and full stop, then the keyword style, an equals sign and then the formatting options for the level in curly brackets. In the curly brackets we need to specify a level distance and a sibling angle:
\begin{tikzpicture}[grow cyclic, text width=2.7cm, align=flush center,
level 1/.style={level distance=5cm,sibling angle=90},
level 2/.style={level distance=3cm,sibling angle=45}]
The level distance is the distance between the centres of the child nodes and the centre of the node connected above it. We've set the level distances to 5cm in level one and 3cm in level two. This means that the distance between the mind map title and the series titles is 5cm and the distance between the the series titles and the individual videos is 3cm. The sibling angle is the angle between the branches. As we only have four branches at the top of level 1 we've given level 1 a sibling angle of 90 degrees. As we have many more branches coming out of the first generation nodes we've given level 2 a sibling angle of 45 degrees:

Our tree is now looking pretty good but to turn our tree into a proper mind map we need to make use of the mindmap TikZ library. To do this we add the keyword mindmap into the formatting options. We also need to add the concept option to every node using this code: every node/.style=concept. Then we can set a default colour for all the nodes using concept color= followed by a colour. We'll choose an orange. Finally we also need to add the key word append in after the full stop in our level style specifications:
\begin{tikzpicture}[mindmap, grow cyclic, every node/.style=concept, concept color=orange!40,
level 1/.append style={level distance=5cm,sibling angle=90},
level 2/.append style={level distance=3cm,sibling angle=45},]
Now if we compile the code we'll see TikZ has generated some nice bubble shapes and links to turn our tree into an aesthetically pleasing mind map:

Finally we can edit the colours of the different nodes and their children. To do this we simply add a pair of square brackets after the keyword child and use them to specify a concept colour. Note that specifying a concept colour at this point will affect all the nodes down from it. Let's give each of the four series a separate colour. We'll also give the Mind Maps node a different colour as it is the one we are creating now:
child [concept color=blue!30] { node {Beginners Series}
...
child [concept color=yellow!30] { node {Thesis Series}
...
child [concept color=teal!40] { node {Beamer Series}
...
child [concept color=purple!50] { node {TikZ Series}
...
child [concept color=green!40] { node {Mind Maps}}

Download 1.76 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling