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 have an issue with the vertical alignment of circled text with TikZ. This basic code causes the problem I have.

  \texttt{some text here =}
  \tikz[remember picture] \node[draw,ellipse,fill=none,thick] (code) {\texttt{other text}};

The problem is that the displayed text 'some text here=' is not vertically aligned with the displayed text 'other text'. I read about anchors in the documentation and they looked promising, but I've been unable to get them to work for me so far. Perhaps I could do this by making the left hand side a node, but I don't think that should be necessary? Any suggestions would be much appreciated!

share|improve this question
    
You should add to the \tikz options baseline=-0.825ex: that should fix the problem. –  Claudio Fiandrino Aug 18 '12 at 13:53
1  
Thanks Claudio! Worked a treat. –  John Pirie Aug 18 '12 at 13:57
add comment

2 Answers

Use the base of the node for the baseline option:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\texttt{some text here =}
\tikz[remember picture,baseline=(code.base)] \node[draw,ellipse,fill=none,thick] (code) {\texttt{other text}};

\end{document}

enter image description here


Edited by Claudio Fiandrino

This is a possible alternative:

\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\texttt{some text here = \tikz[baseline=-0.825ex] \node[draw,ellipse,fill=none,thick] (code) {other text};}
\end{document}

Notice that if you insert the tikz code inside the first texttt you can skip the command inside the node since it is automatically rendered in typewriter.

share|improve this answer
    
I've added the alternative present in my previous answer; hope you don't mind. :) –  Claudio Fiandrino Aug 18 '12 at 14:37
    
@ClaudioFiandrino not at all. :-) –  Gonzalo Medina Aug 18 '12 at 14:45
add comment
 \texttt{some text here =}
  \tikz[remember picture,baseline] 
   \node[draw,ellipse,fill=none,thick,anchor=base] (code) {\texttt{other text}};
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.