5

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!

2 Answers2

5

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.

Gonzalo Medina
  • 505,128
4
 \texttt{some text here =}
  \tikz[remember picture,baseline] 
   \node[draw,ellipse,fill=none,thick,anchor=base] (code) {\texttt{other text}};
Guido
  • 30,740