Putting text at the side of a tikzpicture
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:
\node[text width=6cm, anchor=west, right] at (5,0)
{In this diagram, what can you say about $\angle F$, $\angle B$ and $\angle E$?};
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
\begin{tikzpicture}
% Your code
\end{tikzpicture}
In this diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
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:
\clip(-4.3,-5.44) rectangle (18.7,6.3);
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:
\begin{tikzpicture}
% Your code
\end{tikzpicture}
\parbox[b]{4cm}{
In this diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
}
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. Fortunately tikz
has a simple option for this:
\begin{tikzpicture}[baseline=0, ...remaining options...]
% Your code
\end{tikzpicture}
\hskip{1cm}\parbox{4cm}{
In this diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
}
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 around 4
units, so I could use baseline=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 option baseline=(current bounding box.north)
.
Second, the [t]
option for parbox
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:
\fbox{\begin{tikzpicture}[baseline=(current bounding box.north), ...]
% Your code
\end{tikzpicture}}
\parbox[t]{4cm}{\vskip0pt
In this diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
}
You can use two minipage
environment. If you need to clip your picture, you can use trim left
and trim right
see the pgfmanual for explanations.
You don't need to load pgf
but only tikz
and you can reduce your code.
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,scale=.6,font=\scriptsize]
\draw (0,0) circle (4.01cm) node [above]{$A$};
\draw (-4.01,0) node[left] {$C$}
-- (0,0)
-- (4.01,0) node [right]{$D$}
-- (-0.28,4)node[above] {$B$}
-- (-4.01,0)
-- (1.62,3.67)node[above] {$E$}
-- (4.01,0)
-- (-2.27,3.3) node[above] {$F$} -- cycle;
\fill [color=black] (0,0) circle (1.5pt)
(-0.28,4) circle (1.5pt)
(-4.01,0) circle (1.5pt)
(4.01,0) circle (1.5pt)
(1.62,3.67) circle (1.5pt)
(-2.27,3.3) circle (1.5pt);
\end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
In the following diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
\end{minipage}
\end{document}
Now if you want to put the text and the figure at its top
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.north),line cap=round,line join=round,>=triangle 45,scale=.6,font=\scriptsize]
\draw (0,0) circle (4.01cm) node [above]{$A$};
\draw (-4.01,0) node[left] {$C$}
-- (0,0)
-- (4.01,0) node [right]{$D$}
-- (-0.28,4)node[above] {$B$}
-- (-4.01,0)
-- (1.62,3.67)node[above] {$E$}
-- (4.01,0)
-- (-2.27,3.3) node[above] {$F$} -- cycle;
\fill [color=black] (0,0) circle (1.5pt)
(-0.28,4) circle (1.5pt)
(-4.01,0) circle (1.5pt)
(4.01,0) circle (1.5pt)
(1.62,3.67) circle (1.5pt)
(-2.27,3.3) circle (1.5pt);
\end{tikzpicture}
\hfill
\begin{minipage}{0.5\textwidth}
In the following diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?
\end{minipage}
\end{document}
Package tcolorbox
also offers another way of distributing graphics/tabulars and text side by side. \tcbsidebyside
box accepts two parameters, left and right contents to be distributed side by side, and sidebyside adapt
option allows to declare which part will define space distribution. sidebyside align
defines vertical alignment of both parts.
With TikZ
code taken from Alain's answer, the result could be:
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[most]{tcolorbox}
\pagestyle{empty}
\begin{document}
\tcbsidebyside[sidebyside adapt=left, blanker, sidebyside gap=1cm,
sidebyside align=top seam]{%
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,scale=.6,font=\scriptsize]
\draw (0,0) circle (4.01cm) node [above]{$A$};
\draw (-4.01,0) node[left] {$C$}
-- (0,0)
-- (4.01,0) node [right]{$D$}
-- (-0.28,4)node[above] {$B$}
-- (-4.01,0)
-- (1.62,3.67)node[above] {$E$}
-- (4.01,0)
-- (-2.27,3.3) node[above] {$F$} -- cycle;
\fill [color=black] (0,0) circle (1.5pt)
(-0.28,4) circle (1.5pt)
(-4.01,0) circle (1.5pt)
(4.01,0) circle (1.5pt)
(1.62,3.67) circle (1.5pt)
(-2.27,3.3) circle (1.5pt);
\end{tikzpicture}%
}{In the following diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?}
\end{document}
And without blanker
option, all tcolorbox
bells and whistles can be applied:
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[most]{tcolorbox}
\pagestyle{empty}
\begin{document}
\tcbsidebyside[title=A \texttt{\textbackslash{}tcbsidebyside} example,
sidebyside adapt=left,
sidebyside gap=1cm,
bicolor, colback=green!10, colbacklower=yellow!10, drop lifted shadow, fonttitle=\bfseries]{%
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,scale=.6,font=\scriptsize]
\draw (0,0) circle (4.01cm) node [above]{$A$};
\draw (-4.01,0) node[left] {$C$}
-- (0,0)
-- (4.01,0) node [right]{$D$}
-- (-0.28,4)node[above] {$B$}
-- (-4.01,0)
-- (1.62,3.67)node[above] {$E$}
-- (4.01,0)
-- (-2.27,3.3) node[above] {$F$} -- cycle;
\fill [color=black] (0,0) circle (1.5pt)
(-0.28,4) circle (1.5pt)
(-4.01,0) circle (1.5pt)
(4.01,0) circle (1.5pt)
(1.62,3.67) circle (1.5pt)
(-2.27,3.3) circle (1.5pt);
\end{tikzpicture}%
}{In the following diagram, what can you say about $\angle F$, $\angle B$ and$\angle E$?}
\end{document}