我正在尝试创建一个包含 groupplot 的 TikZ 图片(使用 pgfplots)。我需要在 y 轴标签中为单位添加一个直立的 mu。在我之前没有使用 groupplots 的图中,我没有遇到任何问题,但在这个特定情况下,它会发送一个错误
缺少插入 $。\nextgroupplot[height=1.11cm]
产生该错误的代码是:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, plotmarks, pgfplots.groupplots, pgfplots.units}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{upgreek} % For non-italic greek letters
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2, vertical sep= 0.62cm},
width=8.5cm,
scale only axis, % To ensure same size on all pictures axis
restrict y to domain=-5:40]
% Plot main figure (a)
\nextgroupplot[height=5.48cm,
every axis y label/.append style={at=(ticklabel cs:0.3)},
ylabel = Vertical deflection z (\upmu)]
\addplot coordinates {(0,30) (6,5)};
% Plot zoom (b)
\nextgroupplot[height=1.11cm]
\addplot coordinates {(0,-0.2) (6,-0.1)};
\end{groupplot}
\end{tikzpicture}
\end{document}
请注意,以下代码(除用\upmu
m 替换外,其他均相同)有效:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, plotmarks, pgfplots.groupplots, pgfplots.units}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{upgreek} % For non-italic greek letters
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2, vertical sep= 0.62cm},
width=8.5cm,
scale only axis, % To ensure same size on all pictures axis
restrict y to domain=-5:40]
% Plot main figure (a)
\nextgroupplot[height=5.48cm,
every axis y label/.append style={at=(ticklabel cs:0.3)},
ylabel = Vertical deflection z (m)]
\addplot coordinates {(0,30) (6,5)};
% Plot zoom (b)
\nextgroupplot[height=1.11cm]
\addplot coordinates {(0,-0.2) (6,-0.1)};
\end{groupplot}
\end{tikzpicture}
\end{document}
并给出以下结果:
你能帮助我了解问题出在哪里吗?
谢谢你!
答案1
问题是\upmu
(从包装上看upgreek
)是为设计的math mode
,但您在图片中使用了text mode
。您的线路应该是
ylabel = Vertical deflection z ($\upmu$)]
\upmu
在 中使用math mode
。以下是有效的 MWE:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, plotmarks, pgfplots.groupplots, pgfplots.units}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{upgreek} % For non-italic greek letters
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2, vertical sep= 0.62cm},
width=8.5cm,
scale only axis, % To ensure same size on all pictures axis
restrict y to domain=-5:40]
% Plot main figure (a)
\nextgroupplot[height=5.48cm,
every axis y label/.append style={at=(ticklabel cs:0.3)},
ylabel = Vertical deflection z ($\upmu$)]
\addplot coordinates {(0,30) (6,5)};
% Plot zoom (b)
\nextgroupplot[height=1.11cm]
\addplot coordinates {(0,-0.2) (6,-0.1)};
\end{groupplot}
\end{tikzpicture}
\end{document}```