考虑下面的 MWE。
\documentclass{memoir}
%---------------------------------------------------------------%
\usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[labelsep=space,
labelfont={sf,bf},
textfont=sf,
justification=RaggedRight,
caption=false]{subfig}
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{angles,
quotes,
% added for compatibility with babel ...
babel
}
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
\tikzset{
MA/.style args = {#1/#2}{% My Angle label position!
draw, <->,
angle radius=#1,
angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[h]\centering
\subfloat[\label{fig:1.39a}]%
{
\begin{tikzpicture}
%---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\subfloat[\label{fig:1.39br}]%
{
%%%% ht-138b (bandpass signal)
\begin{tikzpicture}
%---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\caption{}
\end{figure}
\end{document}
事实上,它给出了众所周知的错误
! Argument of \language@active@arg> has an extra }.
在某些情况下,当我不使用时\subfloat[...]{...}
,TikZ 库似乎babel
能够处理引号问题;然而,在存在的情况下,\subfloat
情况不再如此。
如何让这些软件包协同工作?
附录: 同时我得到了两个答案。对于我目前的工作来说,@egreg 的回答更有趣。他的两个建议都适用于上述 MWE,但是,实际文档更复杂,建议的补丁失败了。
更接近我的真实文档的 MWE 如下:
\documentclass{memoir}
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[english,slovene]{babel}
\usepackage[labelsep=space, labelfont={sf,bf},
textfont=sf,
format=hang,
justification=RaggedRight,
caption=false]{subfig}
\usepackage{tikz}
\usetikzlibrary{angles,arrows,arrows.meta,
quotes,
babel% for compatibility with babel ...
}
\tikzset{SDVpsp/.style = {%
%%-------------------------------------------------------------%%
LA/.style args = {##1/##2}{%
line width=##1,
draw=##2,%color
arrows={-Straight Barb[]}
},
%%-------------------------------------------------------------%%
LC/.style args = {##1/##2}{%
line width=##1,
draw=##2%color
},
%%-------------------------------------------------------------%%
MA/.style args = {##1/##2}{% My Angle label position
draw, <->,
angle radius=##1,
angle eccentricity=##2},
%%-------------------------------------------------------------%%
every pic quotes/.append style = {%
inner sep=2pt, anchor=west},
%%-------------------------------------------------------------%%
}% end of styles
}% end of tikzset
\newcommand\ce{\mathsf{ce}}
\usepackage{etoolbox}
\makeatletter% <--- sugested by egreg
\patchcmd{\sf@@@subfloat}{#4}{\scantokens{#4\empty}}{}{}
\makeatother
%---------------------------------------------------------------%
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[h]
% \shorthandoff{"}% <--- suggested by egreg
\begin{sidecaption}{}%Fourier transform of $x_{1,pe}(f)$ and $x_{2,pe}(f)$}[fig:1.39]
\centering
\subfloat[Phasor representation of $A\exp^{j2\pi f_c t+\varphi}$ \label{fig:1.39a}]
{
%%%% ht-138a (bandpass signal)
\begin{tikzpicture}[SDVpsp,
LA/.default = 0.3pt/gray,
]
%---
\draw[LA] (-1mm,0) -- (44mm,0) coordinate (B)
node[below left] {$\Re$};
\draw[LA] (0,-1mm) -- (0,44mm) node[below left] {$\Im$};
%---
\draw[LA=1pt/red]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=11mm/1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\hfill
\subfloat[Complex envelope as a (slowly) varying amplitude and phase \label{fig:1.39b}]
{
%%%% ht-138b (bandpass signal)
\begin{tikzpicture}[SDVpsp,
LA/.default = 0.3pt/gray,
MA/.style args = {#1/#2}{% My Angle label position!
draw, <->,
angle radius=#1,
angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
]
%---
\draw[LA] (-1mm,0) -- (44mm,0) coordinate (B)
node[below left] {$x_c$};
\draw[LA] (0,-1mm) -- (0,44mm) node[below left] {$x_s$};
%---
\draw[LC=0.5pt/gray,densely dashed]
(75:38mm) .. controls + (0.0,-0.3) and + (-0.3,0.3) ..
(60:33mm) .. controls + (0.3,-0.3) and + (0.0,+0.3) ..
(45:30mm) node[above right] {$x_\ce(t)$};
%---
\draw[LA=1pt/red]
(0,0) coordinate (O) -- node[above,sloped] {$A(t)$}
(60:33mm) coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\end{sidecaption}
\end{figure}
\end{document}
我观察到:
只有一个补丁
#
会产生错误!Parameters must be numbered consecutively
。我设法使用两个补丁来解决此错误#
,即\patchcmd{\sf@@@subfloat}{##4}{\scantokens{##4\empty}}{}{}
不幸的是这个补丁没有帮助
使用
\shorthandoff{"}
引号解决问题,但是它必须添加到每个图中(如果我理解正确的话,egreg 答案)...所以我非常感兴趣,是否有可能开发一个补丁,它可以按预期工作。
答案1
问题在于TikZ 库通过在开始时更改其类别代码来babel
解决简写问题。但是,当出现在 的参数中时,此类别代码无法更改。"
tikzpicture
tikzpicture
\subfloat
解决方案:使用subcaption
或者补丁\subfloat
来做\scantokens
:
\documentclass{memoir}
%---------------------------------------------------------------%
\usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[
labelsep=space,
labelfont={sf,bf},
textfont=sf,
justification=RaggedRight,
caption=false
]{subfig}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\sf@@@subfloat}{#4}{\scantokens{#4\empty}}{}{}
\makeatother
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{
angles,
quotes,
babel
}
\tikzset{
MA/.style args = {#1/#2}{% My Angle label position!
draw, <->,
angle radius=#1,
angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[h]\centering
\subfloat[\label{fig:1.39a}]{%
\begin{tikzpicture}
%---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}\quad
\subfloat[\label{fig:1.39br}]{%
%%%% ht-138b (bandpass signal)
\begin{tikzpicture}
%---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\caption{Xyz}
\end{figure}
\end{document}
答案2
你应该使用较新的软件包subcaption
包而不是subfig
,并替换\subfloat{...}
为subfigure
环境:
\documentclass{memoir}
%---------------------------------------------------------------%
\usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[labelsep=space,
labelfont={sf,bf},
textfont=sf,
justification=RaggedRight]{subcaption}
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{
angles,
quotes,
% added for compatibility with babel ...
babel
}
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
\tikzset{
MA/.style args = {#1/#2}{% My Angle label position!
draw, <->,
angle radius=#1,
angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[h]\centering
\begin{subfigure}{0.49\textwidth}
\centering
\begin{tikzpicture}
% ---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
% ---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
% ----------------
\end{tikzpicture}
\caption{}
\label{fig:1.39a}
\end{subfigure}
\hfill
\begin{subfigure}{0.49\textwidth}
\centering
%%%% ht-138b (bandpass signal)
\begin{tikzpicture}
% ---
\draw[->] (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->] (0,-1mm) -- (0,33mm);
% ---
\draw[thick,->]
(0,0) coordinate (O) --
(60:33mm) coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
% ----------------
\end{tikzpicture}
\caption{}
\label{fig:1.39br}
\end{subfigure}
\caption{}
\end{figure}
\end{document}