I've just completed a tikz diagram. I need the text
In the following diagram, what can you say about $\angle F$, $\angle
B$ and$\angle E$?
to go to the right of the diagram to save space on the paper.
This is what I have:
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{uuuuuu}{rgb}{0.27,0.27,0.27}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{xdxdff}{rgb}{0.49,0.49,1}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-4.3,-5.44) rectangle (18.7,6.3);
\draw(0,0) circle (4.01cm);
\draw (-4.01,0)-- (0,0);
\draw (0,0)-- (4.01,0);
\draw (-0.28,4)-- (-4.01,0);
\draw (-0.28,4)-- (4.01,0);
\draw (-4.01,0)-- (1.62,3.67);
\draw (1.62,3.67)-- (4.01,0);
\draw (-2.27,3.3)-- (-4.01,0);
\draw (-2.27,3.3)-- (4.01,0);
\begin{scriptsize}
\fill [color=black] (0,0) circle (1.5pt);
\draw[color=black] (0.14,0.28) node {$A$};
\fill [color=black] (-0.28,4) circle (1.5pt);
\draw[color=black] (-0.12,4.28) node {$B$};
\fill [color=black] (-4.01,0) circle (1.5pt);
\draw[color=black] (-3.84,0.28) node {$C$};
\fill [color=black] (4.01,0) circle (1.5pt);
\draw[color=black] (4.16,0.28) node {$D$};
\fill [color=black] (1.62,3.67) circle (1.5pt);
\draw[color=black] (1.78,3.94) node {$E$};
\fill [color=black] (-2.27,3.3) circle (1.5pt);
\draw[color=black] (-2.14,3.58) node {$F$};
\end{scriptsize}
\end{tikzpicture}
\begin{center}
In the following diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
\end{center}
\end{document}
Best Answer
There are two approaches:
1. To include the text as part of the figure
You have to simply add a node inside the
tikzpicture
. It will be useful to limit the width of the text, and to play with anchors to position it at the required place. eg:2. To put the text out of the
tikzpicture
environment.For this solution you have to keep in mind that, for TeX, your complete figure is like a HUGE character, part of a sentence, so you can put your text right after that "character" and TeX will make a paragraph with it
However if you try this with your code, you'll get the following strange result:
This is because you included this line in your figure:
which causes the figure to have a width of 18.7 cm, and height of 6.3cm. This line is unnecessary and can be safely removed, producing:
You can see that the figure is used as a big char, part of a "normal" paragraph. However the result is ugly, because the text warps and continues below the figure.
This can be avoided putting the text inside a
\parbox
which will produce a box of a fixed width containing the text. TeX will treat this whole box as another "big char", and put it next to the figure:Option
[b]
is to specify where is the "baseline" of this box. Baselines are aligned in the same horizontal line when composing a paragraph. The tikz picture has its baseline at its bottom, so if we give[b]
option to the parbox, making it baseline also at the bottom, both will be aligned:If you omit
[b]
in the parbox, the resulting parbox will have its baseline at its center. This will align the center of the parbox with the bottom of the figure, and this is ugly. To get the same output than in case 1 (text embedded in tikz picture), we need to change the baseline of the figure, and put it at its center. Fortunatelytikz
has a simple option for this:Produces:
For completeness I'll include also the case of top-alignment, which is a bit trickier than others. You could think that, to get top alignment, it would be enough to put the
baseline
of the tikz figure at its top, and use[t]
option for the parbox. However this does not work as expected.First, the tikz picture. Which value should I write for
baseline
option? It can accept a number, which is a measure from the bottom border, or the coordinates of a node. In this case, I know (reading the code) that the circle has a radius around4
units, so I could usebaseline=4cm
, but this is not taking into account the space needed for the label B on top, and it is not a general solution. The general solution is to give the optionbaseline=(current bounding box.north)
.Second, the
[t]
option forparbox
does not put the baseline "at the top of that box", but instead "at the basline of the top line of that box". So, the baseline of the first line of text will be aligned with the top border of the figure, as the following figure shows (I added a border to the figure to make more evident the issue):The solution is to include an "empty" line as the first line of the
parbox
. It can be achieved with\vskip0pt
. This will produce a line which has no height or depth, but since it is the first line of the parbox, it will be used as baseline, and it is exactly at the top of that box. This is the code: