我正在尝试将 TikZ 图形用作方程的一部分,但我只能使定位或缩放正确显示。
例如,使用“resizebox”为我的图形提供正确的大小使它们显示如下(放大以便于查看):
如果我指定基线,则似乎会跳过调整大小。
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
\node (start) at (0,1) {};
\node (end) at (1,1) {};
\node (bottom) at (0.5,0) {};
\path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
\path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
\path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}
\newcommand{\rightribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
\begin{scope}[xscale=-1]
\node (start) at (0.3,1) {};
\node (end) at (0.7,1) {};
\node (bottom) at (0.5,0) {};
\path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
\path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
\path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%
}
\newcommand{\ribcup}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}%[baseline={($ (current bounding box) - (0,0pt) $)}]
\begin{scope}[xscale=1]
\node (start) at (-0.5,1) {};
\node (end) at (0.5,1) {};
\node (bottom) at (0,0) {};
\path[color=black, line width=2pt] [out=0, in=-135] (bottom.center) edge (end.west);
\path[color=black, line width=2pt] [out=-45, in=180] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%
}
\begin{document}
\[ \langle \leftribbon \rangle = -A^3\langle\ribcup\rangle \]
\end{document}
答案1
要回答您的问题,您只需使用baseline
如下方法:
\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}[baseline]
\node[inner sep=0pt] (start) at (0,1) {};
\node[inner sep=0pt] (end) at (1,1) {};
\node[inner sep=0pt] (bottom) at (0.5,0) {};
\path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
\path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
\path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}
在你的情况下你需要添加.base
例如这样的:
\newcommand{\leftribbon}{%
\resizebox{!}{10pt}{
\begin{tikzpicture}[baseline= {($(current bounding box.base)-(-2pt,-2pt)$)}]
\node[inner sep=0pt] (start) at (0,1) {};
\node[inner sep=0pt] (end) at (1,1) {};
\node[inner sep=0pt] (bottom) at (0.5,0) {};
\path[color=black, line width=2pt] [out=180, in=-135] (bottom.center) edge (end.west);
\path[color=white, line width=6pt] [out=-45, in=0] (start.east) edge (bottom.center);
\path[color=black, line width=2pt] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
}
我更新了您的代码,并删除了\resizebox
(我认为这里没有必要)首先:如果您愿意,这里比您需要添加的coordinate
更好。我添加了一些样式以轻松修改结果。node
inner sep=0pt
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{char/.style = { color=black,line width=.6pt}}
\tikzset{effet/.style = { color=white,line width=1.2pt}}
\newcommand{\leftribbon}[1][1]{%
\begin{tikzpicture}[baseline,scale=#1]
\coordinate (start) at (0,10pt) ;
\coordinate (end) at (10pt,10pt) ;
\coordinate (bottom) at (5pt,0) ;
\draw[char] [out=180, in=-135] (bottom.center) edge (end.west);
\draw[effet] [out=-45, in=0] (start.east) edge (bottom.center);
\draw[char] [out=-45, in=0] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
\newcommand{\rightribbon}[1][1]{%
\begin{tikzpicture}[baseline,scale=#1]
\begin{scope}[xscale=-1]
\coordinate (start) at (3pt,10pt);
\coordinate (end) at (7pt,10pt) ;
\coordinate (bottom) at (5pt,0);
\draw[char] [out=180, in=-135] (bottom.center) edge (end.west);
\draw[effet] [out=-45, in=0] (start.east) edge (bottom.center);
\draw[char] [out=-45, in=0] (start.east) edge (bottom.center);
\end{scope}
\end{tikzpicture}
}%
\newcommand{\ribcup}[1][1]{%
\begin{tikzpicture}[baseline,scale=#1]
\coordinate (start) at (-5pt,10pt) ;
\coordinate (end) at (5pt,10pt) ;
\coordinate (bottom) at (0pt,0pt);
\path[char] [out=0, in=-135] (bottom.center) edge (end.west);
\path[char] [out=-45, in=180] (start.east) edge (bottom.center);
\end{tikzpicture}
}%
\begin{document}
\[
\langle \leftribbon[.8]\rangle = -A^3 \langle\ribcup[.8]\rangle
\]
\end{document}