TransWikia.com

How to write source description under longtables?

TeX - LaTeX Asked on February 14, 2021

I want to be able to add the source information below figures and tables ( longtables included). I have used the idea provided in this post, but it gives the following error for longtables:

! Misplaced noalign.
caption ->noalign

Is it possible to fix and have a single command that would for those enviroments?

Here is a minimal code to reproduce it.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{graphicx}
usepackage{caption}
usepackage{longtable,booktabs}
usepackage{blindtext}

newcommand{source}[1]{
 vspace{1ex}caption*{textbf{Source:} {#1}}
}

begin{document}

begin{table}[h]
caption{Test - Table}label{t:test}
begin{tabular}{p{0.5textwidth} p{0.5textwidth}}
toprule
blindtext & blindtext 
bottomrule
end{tabular}
source{Test Test}
end{table}

newpage

begin{longtable}{p{0.5textwidth} p{0.5textwidth}}
caption{Test - Longtable} label{lt:test} 
toprule
blindtext & blindtext 
midrule
blindtext & blindtext 
midrule
blindtext & blindtext 
bottomrule
source{Test longtable 123}
end{longtable}

newpage

begin{figure}[h]
 centering
 includegraphics[width=0.5textwidth]{example-image-a}
 caption{Test123.}label{fig-img-a}
 source{Test image.}
end{figure}

end{document}

One Answer

The longtable environment does not like the combination of vspave plus caption, at least not without an extra between them.

Solution: Do not use vspave but let caption do the skip, for example:

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{graphicx}
usepackage{caption}
usepackage{longtable,booktabs}
usepackage{blindtext}

newcommand{source}[1]{
 captionsetup{skip=1ex,position=b}%
 caption*{textbf{Source:} {#1}}
}

begin{document}

begin{table}[h]
caption{Test - Table}label{t:test}
begin{tabular}{p{0.5textwidth} p{0.5textwidth}}
toprule
blindtext & blindtext 
bottomrule
end{tabular}
source{Test Test}
end{table}

newpage

begin{longtable}{p{0.5textwidth} p{0.5textwidth}}
caption{Test - Longtable} label{lt:test} 
toprule
blindtext & blindtext 
midrule
blindtext & blindtext 
midrule
blindtext & blindtext 
bottomrule
source{Test longtable 123} 
end{longtable}

newpage

begin{figure}[h]
 centering
 includegraphics[width=0.5textwidth]{example-image-a}
 caption{Test123.}label{fig-img-a}
 source{Test image.}
end{figure}

end{document}

Correct answer by P.M. on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP