tikzpicture 環境を align 環境で適切にフォーマットする方法

tikzpicture 環境を align 環境で適切にフォーマットする方法

align 環境内で tikzpicture 環境を使用する方法を見つけようとしましたが、私が見つけた答えに最も近いものは次のとおりです。align または gather 環境での tikzpicture マトリックスの使用ただし、これは tikzlibrary の使用に関係し、特に行列を中心に展開されるため、私の質問には答えていません。

自分で少し調べて、図3.20のコードを見てみたところ、https://tikz.org/examples/chapter-03-drawing-positioning-and-aligning-nodes/私は次のものを作ることができました:

私自身の環境利用の試み

MWE は次のとおりです。

\documentclass{article}

\usepackage{amsmath, tikz}

\begin{document}

\begin{align*}
x_1 = \frac{
\tikz[baseline=(label.base)] \node[circle, draw=red, text=blue, inner sep=1pt, very thick](label){0};
^2-2}{\tikz[baseline=(label.base)] \node[circle, draw=red, text=blue, inner sep=1pt, very thick](label){0};
^2-2\cdot \tikz[baseline=(label.base)] \node[circle, draw=red, text=blue, inner sep=1pt, very thick](label){0};
}
\end{align*}

\begin{align*}
\begin{tikzpicture}[rcirc/.style={circle, draw=red, text=blue, very thick, inner sep=1pt}, baseline=(label.base)]
    \(x_1 = \frac{\tikz \node[rcirc](label){0};^2-2}{\tikz \node[rcirc](label){0};^2-2\cdot \tikz \node[rcirc](label){0};}\)
\end{tikzpicture}
\end{align*}

\end{document}

ご覧のとおり、すべてのコマンドを手動で挿入すると、完全に正常に動作します。tikzpicture 環境を利用してプロセスを「自動」にしようとすると、書式設定で問題が発生します。tikzpicture を使用した場合と使用しない場合で同じ結果が得られるように修正することは可能ですか? 私はまだ LaTeX に比較的慣れておらず、まずシンプルさに基づいて強固な基盤を構築し、その後拡張しようとしているため、シンプルなソリューションが望ましいですが、複雑なソリューション以外に選択肢がない場合は、そうします。

編集: ネスト機能は基本的に tikzpicture ではサポートされていないことがわかりました (詳細についてはコメントを参照してください)。そのため、元の質問を少し変更すると、math の align 環境のように機能し、私が提供した最初の例のように適切にフォーマットする tikzpicture 環境を作成する方法になります。

答え1

特定のコマンドを定義します:

\documentclass{article}

\usepackage{amsmath, tikz}

\newcommand{\circlednumber}[1]{%
  {\tikz[baseline=(label.base)] \node[circlednumber](label){#1};}%
}
\tikzset{
  circlednumber/.style={circle, draw=red, text=blue, inner sep=1pt, very thick},
}

\begin{document}

\begin{align*}
x_1 &= \frac{\circlednumber{0}^2-2}{\circlednumber{0}^2-2\circlednumber{0}}
\\
x_2 &= \frac{\circlednumber{1}^2-2}{\circlednumber{1}^2-2\circlednumber{1}}
\end{align*}

\end{document}

原則として、align単一の方程式には使用しないでください。

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

関連情報