我制作了一份漂亮的报告,从 CSV 文件中获取所有数据,data.csv
如下所示:
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme
img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
img2(points1),Temps (en ms),0,1,4,3,3,2,3,123
img2(points1),Erreur MSE,6.28,3.83,3.83,3.24,3.28,2.69,2.36,2.56
img2(points1),Erreur DeltaE,0.79,1.09,1.09,0.72,0.72,0.63,0.34,0.60
img2(points1),Erreur PSNR (en dB),40.15,42.30,42.30,43.02,42.97,43.83,44.41,44.05
...
我已经编写了许多宏,例如下面的宏,它读取#1
使用给定算法生成的图像的 MSE 误差#2
(温柔一点,这是我第一次编写自己的宏!):
\newcommand{\MSE}[2]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
尽管如此,我似乎无法在图形(以及子图形)的标题中使用我的宏。这是一个失败的最小示例:
\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme
img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\newcommand{\MSE}[2]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\caption{A caption \MSE{img1(illusion)}{\BilineaireA} }
\end{figure}
\end{document}
我可以读取! TeX capacity exceeded
。如果我将命令放在minipage
环境中,则会收到以下错误:
Argument of \@caption has an extra }
感谢您的帮助 !
答案1
错误消息,例如
Argument of \@caption has an extra }
通常意味着 参数中的命令\caption
需要保护。在这种情况下,命令肯定是\MSE
。因此
\caption{A caption \protect\MSE{img1(illusion)}{\BilineaireA}}
可能会解决问题。
但是,在这个特定的应用中,\protect
这还不够。我们需要包含所需值的东西,因此可以采取不同的方法。定义一个类似的\MSEset
宏,它也接受一个可选参数(默认值\MSEresult
:
\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme
img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\newcommand{\MSE}[2]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
\newcommand{\MSEset}[3][\MSEresult]{%
\csvreader[ head to column names,%
before filter=\ifthenelse{ \equal{\Images}{#2} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{\xdef#1{#3}}%
}
\newbox{\remibox}
\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\MSEset{img1(illusion)}{\BilineaireA}
\caption{A caption \MSEresult}
\end{figure}
\end{document}
您可以在输入之前设置宏,\caption
并使用\result
代表值。您也可以说
\MSEset[\MSEresultA]{img1(illusion)}{\BilineaireA}
或者如果您需要多个这样的数字,可以使用任何您想要的控制序列。请注意使用其他地方未使用的控制序列名称(如MSE
should do 之类的常用前缀)。
如果需要的话,这还会在图表列表中打印正确的值。
答案2
您是否尝试过将标题保存起来,lrbox
然后使用命令从标题中调用\usebox
?
以下是一些示例代码:
\newsavebox{\mycaption}
\begin{lrbox}{\mycaption}
\begin{minipage}{1in}
\MSE{img1(illusion)}{\BilineaireA}
\end{minipage}
\end{lrbox}
\begin{figure}
\centering
My Image
\caption{\usebox{\mycaption}}
\end{figure}