An error message such as
Argument of \@caption has an extra }
usually means that a command in the argument of \caption
needs protection. In this case the command is surely \MSE
. Thus
\caption{A caption \protect\MSE{img1(illusion)}{\BilineaireA}}
might solve the problem.
However, in this particular application \protect
is not sufficient. We need something that contains the value we need, so a different road can be taken. Define a similar \MSEset
macro, that takes also an optional argument (default value \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}
You set the macro before typing the \caption
and use \result
to stand for the value. You can also say
\MSEset[\MSEresultA]{img1(illusion)}{\BilineaireA}
or any control sequence you want if you need more than one of these numbers. Take care of using control sequence names that are not used elsewhere (a common prefix such as MSE
should do).
This will print the correct value also in the List of Figures, should you need it.
The package siunitx
could be a solution for you, but it requires some adjustment of the excel2latex
output, which I'll explain below. siunitx
defines a special column type, S
used in place of the usual l
,c
,r
specifications.
Each cell entry is then taken as the argument to siunitx
's \num{}
command, which accepts scientific notation input as 1.00E-02.
One behavior of this solution is that siunitx
centers the columns around the decimal separator. siunitx
tries to be smart about what is text/headings and what is numerical data. But anything that could be mistaken for numerical data (in your example, the first row, which I'm assuming contains headings) should be protected with curly braces.
So, to apply this solution to excel2latex
output, you'll have to:
- load the
siunitx
package in the document preamble,
- change column specifiers from
c
(or l
or r
) to s
in the beginning of the tabular
environment for any columns with numerical data, and
- protect any non-numerical data that shouldn't be aligned at the decimal separator with curly braces
{}
.
An example:
Before:
\begin{tabular}{cc}
1 & 2 \\
1.00E-02 & 1.05E-03 \\
\end{tabular}
After:
\begin{tabular}{SS}
{1} & {2} \\
1.00E-02 & 1.05E-03 \\
\end{tabular}
Complete Code and Output:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{SS}
{1} & {2} \\
1.00E-02 & 1.05E-03 \\
\end{tabular}
\end{document}
Many adjustments can be made for alignment and spacing of the S
columns. If you decide this solution is workable for you, you can consult the package manual (Section 4.6) for details.
Best Answer
I'm back and I found a partial solution to my problem.
Please keep in mind that I am almost a complete beginner so I'm experimenting. ^^' (I'm using Overleaf to write my code because I tried on RStudio but the datatool package was apparently not available for R version 3.5.1)
So to simplify, this is the pattern I used:
In my particular situation, I am doing a wine list/menu (Carte des Vins) and eventually I want to:
1) sort them by wine (Bordeaux / Burgundy / Port / Rest of the World)
For now I'm using a csv file with only the Bordeaux wines (bordeaux.csv) but ultimately I would like to use a file with all the wines on it (wine.csv)
2) sort them by type (Red / White / Sweet white)
As you will see below, I managed to do that, but maybe there is a better way to do the same thing.
3) format the text as follows:
Vintage Name, Classification (Origin)
ex: 2009 Château Grand Village, Bordeaux Supérieur (Bordeaux)
The only thing that I have trouble with is the comma, because when the Classification column is empty I don't want to get "Vintage Name," with a useless comma... So for now I left the text without a comma.
So this is my whole code:
And this is what I managed to get so far (this is the beginning of my section "Bordeaux" and of my subsection "Red"):