考虑以下代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-feynman}
\begin{document}
$$\begin{tikzpicture}[scale=0.5, baseline=(current bounding box.center)]
\begin{feynman}
\vertex (x);
\vertex[right=of x] (y);
\vertex[above left=of x] (a);
\vertex[below left=of x] (b);
\vertex[above right=of y] (c);
\vertex[below right=of y] (d);
\diagram*{
(x) --[fermion, half left] (y),
(x) --[anti fermion, half right] (y),
(a) --[charged scalar] (x),
(x) --[charged scalar] (b),
(y) --[anti fermion] (c),
(y) --[fermion] (d),
};
\end{feynman}
\end{tikzpicture}$$
\end{document}
尽管我scale=0.5
在 tikzpicture 环境中添加了选项,但缩放似乎不起作用。我该如何解决这个问题?
答案1
该键scale
仅作用于坐标,而不作用于节点的大小。如果使用,scale=0.5, transform shape
节点也会缩放。如果要将其应用于每张图片,可以使用
\tikzset{every picture/.style={
scale=0.5, transform shape,
}}
但请注意,箭头和线宽并不随图片缩放(它们与线宽一致);解决这个问题并不简单。
如果您想要无缝扩展,最好的选择也许是使用\scalebox
。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-feynman}
\newcommand{\diagram}{%
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{feynman}
\vertex (x);
\vertex[right=of x] (y);
\vertex[above left=of x] (a);
\vertex[below left=of x] (b);
\vertex[above right=of y] (c);
\vertex[below right=of y] (d);
\diagram*{
(x) --[fermion, half left] (y),
(x) --[anti fermion, half right] (y),
(a) --[charged scalar] (x),
(x) --[charged scalar] (b),
(y) --[anti fermion] (c),
(y) --[fermion] (d),
};
\end{feynman}
\end{tikzpicture}%
}
\begin{document}
Normal:
\[ \diagram \]
\begingroup %this will make the changes to every picture local
\tikzset{every picture/.style={
,scale=0.5, transform shape
}}
Scale and transform shape:
\[\diagram\]
\endgroup
Using \texttt{scalebox}:
\[\scalebox{0.5}{\diagram}\]
\end{document}
但请注意以下警告:
Package tikz-feynman Warning: Consider loading TikZ-Feynman with \usepackage[co
mpat=1.1.0]{tikz-feynman} so that you can be warned if TikZ-Feynman changes. on
input line 26.