円で囲まれたテキストの TikZ 垂直配置

円で囲まれたテキストの TikZ 垂直配置

TikZ で円で囲んだテキストの垂直方向の配置に問題があります。この基本コードが問題の原因です。

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

問題は、表示されるテキスト「some text here=」が、表示されるテキスト「other text」と垂直に揃っていないことです。ドキュメントでアンカーについて読みましたが、有望に思えましたが、今のところうまく機能していません。左側をノードにすることで実現できるかもしれませんが、それは必要ないと思います。何かご提案があれば、ぜひお願いします。

答え1

baseオプションにはノードの を使用しますbaseline

\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}

ここに画像の説明を入力してください


編集者:クラウディオ・フィアンドリーノ

考えられる代替案は次のとおりです:

\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}

tikz最初の内部にコードを挿入すると、texttt自動的にタイプライターでレンダリングされるため、ノード内のコマンドをスキップできることに注意してください。

答え2

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

関連情報