Attention: there is an error in your code. You missed closing brace }
before [2]
.
The code
\newcommand{\minitab}[2][c]{\begin{tabular}{#1}#2\end{tabular}}
defines the command \minitab
which has two arguments.
The 1st is optional and has default value c
(which will be used if you don't use another value). It is used to determine the alignment of the single column of tabular
. So it could be also r
ight or l
eft.
The second argument is obligatory and it is in fact the content for the tabular
.
So you can use the command as
\minitab{foo and foo}
or
\minitab[l]{foo and foo}
Recall that options for a command are passed in brackets and mandatory arguments in braces. \command[<optional>]{<mandatory>}
.
Edit:
command name: \minitab
number of arguments: [2]
(so the #1
is optional; the #2
is mandatory)
default value for #1
: [c]
(will be overridden if you pass another valid value)
what to do with the arguments? use #2
inside the tabular
as its contents; use #1
for the column alignment in tabular
.
(!) so you have to use {#1}
in the definition. Also, for example, if you want to insert a right border you should use {#1|}
. The braces are important to group.
Recall that the right way to use a tabular
is:
\begin{tabular}{cols}
content...
\end{tabular}
In resume: \minitab[l]{a lot of text}
will be the same as
\begin{tabular}{l}
a lot of text
\end{tabular}
You can use \NewDocumentCommand
.
\NewDocumentCommand{\hlc}{O{yellow}m}{\sethlcolor{#1}\hl{#2}}
\NewDocumentCommand{\hlcite}{oom}{%
\hlc[green]{%
\IfNoValueTF{#1}{% no optional argument
\parencite{#3}%
}{%
\IfNoValueTF{#2}{% just one optional argument
\parencite[#1]{#3}%
}{% both optional arguments
\parencite[#1][#2]{#3}%
}%
}%
}% end of \hlc
}
Note that you don't want a space between \sethlcolor{#1}
ad \hl{#2}
.
Best Answer
Another solution using
xparse
.xparse
uses a different (an in my eyes easier and more flexible) syntax to define a command. The second argument of\NewDocumentCommand
takes a list defining the arguments, e.g.o
for an optional anm
for a mandatory argument. With\If(No)Value(TF)
you can test whether the argument has a value.(TF)
can beT
orF
to test only one case orTF
to differentiate between both the latter case has there arguments, e.g.{#1}{true code}{false code}
. Withd
as argument specifier (see\Bf
definition) you can even define the delimiting symbols,()
in this case, so the code equals the output even more.As daleif said you can add a
\smash
to the subscript to prevent it form affecting the line spacing.without
\smash
(exaggerating example using\sum
and\left…\right
to get flexible parens).with
\smash