Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
:-D JLDiaz thanks! wow so many smart people tonight –  Lorraine Jane Feb 21 '13 at 10:19
add comment

2 Answers

up vote 8 down vote accepted

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$?};

in picture

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:

Strange

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:

Paragraph

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:

Bottom 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:

Aligned at center

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):

Bad alignment

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$?
}

Correct alignment

share|improve this answer
    
For the sake of completeness, it would be interesting to see the code to align the figure and the parbox at its top. tks –  La Raison Feb 21 '13 at 12:07
    
@LaRaison Ok, I've updated the answer –  JLDiaz Feb 21 '13 at 15:40
    
Very nice trick! –  La Raison Feb 22 '13 at 16:43
add comment

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} 

enter image description here

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} 

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.