Captioned images / figures in LaTeX


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

Colour filling


Now lets add a shape onto our grid and colour it in. To do this we use the \fill command instead of the \draw command. Then in square brackets we enter a colour. For example, this specifies a colour that is 40% blue mixed with 60% white. Then we just specify a closed shape as we would normally:
\fill[blue!40!white] (0,0) rectangle (4,4);

If we wanted to add a border around this shape we could change it to the \filldraw command and then alter the arguments so that we have both a fill colour and a draw colour specified:
\filldraw[fill=blue!40!white, draw=black] (0,0) rectangle (4,4);

If instead of one solid colour we want a colour gradient, we could change it to the \shade command. Then in the square brackets we specify a left colour and a right colour:
\shade[left color=blue,right color=red] (0,0) rectangle (4,4);

Instead of doing it from left to right we could do it from top to bottom:
\shade[top color=blue,bottom color=red] (0,0) rectangle (4,4);

Or we could even change it by specifying an inner and outer colour like this:
\shade[inner color=blue,outer color=red] (0,0) rectangle (4,4);

Finally we could also add a border to this by using the \shadedraw command and adding a draw colour:
\shadedraw[inner color=blue,outer color=red, draw=black] (0,0) rectangle (4,4);

Axes


Let's finish this post by adding some labeled axes to our grid. To do this we draw two normal lines both from (0,0), but we'll make them thick and add arrowheads using a dash and a pointed bracket:
\draw[thick,->] (0,0) -- (4.5,0);
\draw[thick,->] (0,0) -- (0,4.5);

We can also label our axes using nodes. To do this we add the keyword node into both \draw statements next to the end co-ordinates, followed by an anchor specification in square brackets and the text in curly brackets. Every node we create in TikZ has a number of anchors. So when we specify the north west anchor for the x-axis node, we are telling TikZ to use the anchor in the top-left-hand corner to anchor the node to the co-ordinate:
\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west] {x axis};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east] {y axis};

To finish our axes we can add in ticks and numbering like this:
\foreach \x in {0,1,2,3,4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};

This clever piece of code uses two for each loops to systematically go along the axes adding the ticks and numbers. In each one, the variable x or y takes on all of the numbers in the curly brackets, each in turn and executes the \draw command.
This concludes our discussion on basic drawing in TikZ. If you want to play around with the document we created in this post you can access it here. In the next post we'll look exporting TikZ code from GeoGebra.
Let's start by creating a simple diagram in GeoGebra. First we'll add a circle using the Circle with Centre through Point tool:

Next we'll add a polygon inside our circle using the Polygon tool:

Then we'll measure an angle inside this polygon using the Angle tool:

Now we'll add a straight line going through two points on the circle using the Line through Two Points tool:

We'll finish up by turning the grid on. To do this we select the Move tool, right click on the background and select the Grid option:

Now to export this as TikZ code we open the file menu, hover over Export and click on Graphics View as PGF/TikZ:

We then tell GeoGebra how much of the grid we want included in our tikzpicture by altering the x and y minimum and maximum points. You'll see a blue box represent this area on the grid. Next we check the format is set to LaTeX article class and then click the generate button:

Now if we hit Copy to Clipboard we can then paste it into an empty tex file. You'll notice that it has generated a preamble where it loads up the tikz package and a TikZ library, it sets the page style to empty and it also defines a new command:
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\newcommand{\degre}{\ensuremath{^\circ}}
Then it begins the document and defines some colours before opening a tikzpicture environment:
\definecolor{qqwuqq}{rgb}{0,0.39,0}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{xdxdff}{rgb}{0.49,0.49,1}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
If we compile the code we'll see it appear in the document. As it's generated from TikZ code rather than an image, it's very high quality:

We could also turn the TikZ picture into a figure to give us more control over things like positioning. To do this we simply enclose the tikzpicture environment in the figure environment. We can then add a placement specifier, a caption and a label:
\begin{figure}[!h]

\label{circle1}
\caption{TikZ from GeoGebra}
\end{figure}
Now if we want to include this figure in an existing document we can copy over everything in the figure environment. We also need to make sure we copy over the relevant parts of the preamble if they're not in our existing docs preamble already. Therefore we'll copy over the \usepackage command and \usetikzlibrary command as well as the \newcommand definition. Finally we also need to copy over the colour definitions.

If we go back to GeoGebra we can alter the way our diagram looks by right clicking on it and changing the object properties. For example we can change colours, point styles, line styles and line thickness.

Another useful thing we can do with GoeGebra is export to Tikz in a beamer format so that we can add diagrams into presentations. To do this we export like before except we select the LaTeX (beamer class) option:

If we now copy this into a blank .tex file and compile the document you'll notice it has generated a number of slides which build up the diagram piece-by-piece:



This is due to the \onslide overlay specifications that GeoGebra has automatically generated for us. For example this \onslide command tells beamer to show the circle from slide four onwards:
\onslide<4->{
\draw [color=ffqqtt] (2,1) circle (2.82cm);
}
We can edit these overlay specifications to make the diagram come together in whatever way we want. For example we may want to make the circle appear on the same slide that point B appears. To do this we change this \onslide command from <4-> to <3-> and then, as the circle was the only item to appear on slide four, we knock the numbering of all overlay specifications above four down by one. Again if you want to add this frame into another beamer presentation you can just copy over all the relevant parts as we did with the document earlier.
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

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