我想將 tikzpicture 第一行的基線與周圍文字的基線對齊,以獲得類似的結果
Let A → B be a function from A to B
a → f(a)
但目前,tikzpicture 垂直居中。我的程式碼是
Let
\begin{tikzpicture}[baseline=-2.6pt,description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of math nodes, row sep=0em, column sep=2em, text height=1.75ex, text depth=.25ex, column 2/.style={anchor=base west}]
{
A & B \\
a & f(a) \\
};
\path[->]
(m-1-1) edge node[above] {$f$} (m-1-2);
\path[|->]
(m-2-1) edge (m-2-2);
\end{tikzpicture}
be a function from A to B.
答案1
你得到你想要的aligned
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let
$\!\begin{aligned}[t]
A &\overset{f}{\longrightarrow} B\\
a &\longmapsto f(a)\end{aligned}$
be a function from $A$ to $B$.
\end{document}
但最好不要內聯這麼大的物件。我更願意
Let $f\colon A\to B$, $a\mapsto f(a)$, be a function from $A$ to $B$.
將分配設定在不同的行上不會添加任何資訊並且會破壞間距。
如果你堅持用 TikZ 來做,這裡是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
Let
\begin{tikzpicture}[
baseline=(m-1-1.base),
description/.style={fill=white,inner sep=2pt}
]
\matrix (m) [
matrix of math nodes,
row sep=0em,
column sep=2em,
text height=1.75ex,
text depth=.25ex,
column 2/.style={anchor=base west}]
{
A & B \\
a & f(a) \\
};
\path[->] (m-1-1) edge node[above] {$\scriptstyle f$} (m-1-2);
\path[|->] (m-2-1) edge (m-2-2);
\end{tikzpicture}
be a function from $A$ to $B$.
\end{document}
答案2
我們,plain TeX 的用戶,不需要tikz
這樣的例子:
Let
\vtop{\halign{$\hfil#{}$&$#\hfil$\cr
A \buildrel f\over\longrightarrow& B\cr
a \longmapsto& f(a)\cr}}
be a function from $A$ to $B$.
\bye