Here's a more flexible macro, that allows to choose between using table
(when the key caption
is used in the optional argument) or just producing the tabular
.
The placement
key (default value htp
) can be added along with the other options.
\documentclass{article}
\usepackage{booktabs}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\conjugation}{O{}m}
{
\group_begin:
\keys_set:nn { froggos/conjugation } { #1 }
\froggos_conjugation:n { #2 }
\group_end:
}
\keys_define:nn { froggos/conjugation }
{
placement .tl_set:N = \l__froggos_conjugation_placement_tl,
placement .initial:n = htp,
caption .tl_set:N = \l__froggos_conjugation_caption_tl,
shortcaption .tl_set:N = \l__froggos_conjugation_shortcaption_tl,
label .tl_set:N = \l__froggos_conjugation_label_tl,
}
\seq_new:N \l__froggos_conjugation_entries_seq
\cs_new_protected:Nn \froggos_conjugation:n
{
\tl_if_empty:NF \l__froggos_conjugation_caption_tl
{
\__froggos_conjugation_table_begin:V \l__froggos_conjugation_placement_tl
\centering
}
\seq_set_split:Nnn \l__froggos_conjugation_entries_seq { \\ } { #1 }
\begin{tabular}{ll}
\toprule
\textbf{Form} & \textbf{Conjugation} \\
\midrule
\textit{Yo} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {1}} \\
\textit{T\'u} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {2}} \\
\textit{\'El} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {3}} \\
\textit{Nosotr@s} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {4}} \\
\textit{Vosotr@s} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {5}} \\
\textit{Ell@s} & \textit{\seq_item:Nn \l__froggos_conjugation_entries_seq {6}} \\
\bottomrule
\end{tabular}
\tl_if_empty:NF \l__froggos_conjugation_caption_tl
{
\tl_if_empty:NTF \l__froggos_conjugation_shortcaption_tl
{
\caption{\l__froggos_conjugation_caption_tl}
}
{
\caption[\l__froggos_conjugation_shortcaption_tl]{\l__froggos_conjugation_caption_tl}
}
\tl_if_empty:NF \l__froggos_conjugation_label_tl
{
\label{\l__froggos_conjugation_label_tl}
}
\end{table}
}
}
\cs_new_protected:Nn \__froggos_conjugation_table_begin:n
{
\begin{table}[#1]
}
\cs_generate_variant:Nn \__froggos_conjugation_table_begin:n {V}
\ExplSyntaxOff
\begin{document}
\listoftables
\section{Main}
\conjugation{soy \\ eres \\ es \\ somos \\ sois \\ son}
\conjugation[
caption=Conjugation of \textit{ser},
label=verb:ser,
]{soy \\ eres \\ es \\ somos \\ sois \\ son}
\conjugation[
caption={Conjugation of \textit{ser}, but with a very long caption that requires a short one},
shortcaption=Conjugation of \textit{ser},
label=verb:ser-again,
]{soy \\ eres \\ es \\ somos \\ sois \\ son}
\end{document}

\centering
from insidetabular
to before tabular. If you like to have centered cells' contents, than replacel
columns type withc
. – Zarko Aug 8 '19 at 8:00table
norcentering
in your code. – egreg Aug 8 '19 at 9:41T\'u
or\'El
. This is the way of type Spanish in prehistoric ages, that is no longer necessary. In a file with UTF8 (the usual today) you can type justTú
andÉl
(but note that the correct for a verb conjugation is "Tu" and "El", without accents). By the way, note also that the RAE do not accept the inclusive language usig the @. – Fran Aug 8 '19 at 11:10