2

I am trying to set up the memoir \legend command to use colon : as the caption separation label, while using dash -- on all other captions. The problem happens when I use my custom memoir \legend command inside a \multicolumn environment.

! Misplaced \noalign.
\captionsetup ->\noalign
                         \bgroup \@ifstar \@captionsetup \@captionsetup
l.36 \end{tabularx}

On the next image, you can see the wrong \legend in red. This is the partial PDF generated with the \legend command throwing the error \noalign. \captionsetup ->\noalign. On the other two green texts, are the labels correctly assigned for caption and legend:

enter image description here

If you remove the line \captionsetup{labelsep=colon}, everything compiles fine, except that all \legends are going to use the default dash -- instead of the colon :

How can I make the first \legend caption inside \multicolumn use colon : instead of dash --?

\documentclass[12pt,a4paper,twoside]{memoir}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{ragged2e}
\RequirePackage{ltablex}\keepXColumns

\makeatletter
\renewcommand{\legend}[2][var]{%
  \M@gettitle{#2}%
  \memlegendinfo{#2}%
  \par
  \begingroup
     \@parboxrestore
     \if@minipage
       \@setminipage
     \fi
     \setlength{\belowcaptionskip}{4pt}
     \captiondelim{:}
     \captionsetup{labelsep=colon}
     \@makecaption{ #1}{\ignorespaces #2}\par
  \endgroup}
\makeatother

\DeclareCaptionLabelSeparator{barr}{~\textendash~}
\captionsetup{format=hang,labelseparator=barr,}

\begin{document}

\begin{tabularx}{\linewidth}{>{\RaggedRight}p{3cm}|>{\arraybackslash}X}
\hline
\multicolumn{2}{p{\dimexpr\textwidth-2\tabcolsep\relax}}{\legend{O autor}}
\endlastfoot
    Cor                          & Branco \\ \hline
\end{tabularx}

\begin{table}[htb]
\caption{Something}
\begin{tabular}{p{2.6cm}p{6.0cm}}
    Meta & Paradigma \\
\end{tabular}
\legend{Something}
\end{table}

\end{document}
  • This seems quite complicated and hacked together. Can you take a step back and describe what you actually want to achieve, output-wise? There is probably a better way to achieve this ... – gernot says Reinstate Monica Nov 8 at 8:42
2

The multicolumn doesn't like the \captionsetup command, but you can set the separator directly:

\documentclass[12pt,a4paper,twoside]{memoir}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{ragged2e}
\RequirePackage{ltablex}\keepXColumns

\makeatletter
\renewcommand{\legend}[2][var]{%
  \M@gettitle{#2}%
  \memlegendinfo{#2}%
  \par
  \begingroup
     \@parboxrestore
     \if@minipage
       \@setminipage
     \fi
     \setlength{\belowcaptionskip}{4pt}%
     \caption@setlabelseparator{colon}%
     \@makecaption{#1}{\ignorespaces #2}\par
  \endgroup}
\makeatother

\DeclareCaptionLabelSeparator{barr}{~\textendash~}
\captionsetup{format=hang,labelseparator=barr,}

\begin{document}

\begin{tabularx}{\linewidth}{>{\RaggedRight}p{3cm}|>{\arraybackslash}X}
\hline
\multicolumn{2}{p{\dimexpr\textwidth-2\tabcolsep\relax}}{\legend{O autor}}
\endlastfoot
    Cor                          & Branco \\ \hline
\end{tabularx}

\begin{table}[htb]
\caption{Something}
\begin{tabular}{p{2.6cm}p{6.0cm}}
    Meta & Paradigma \\
\end{tabular}
\legend{Something}
\end{table}

\end{document}

enter image description here

  • Life savior! Thank you very much!!! – user Nov 9 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.