2

My tables have the captions above and are set with booktabs's \bottomrule at the end. I would like to separate figure (having their caption below) from the text with a \topfigrule

\newcommand{\topfigrule}{\hrule}

but not for tables, as they are already separated enough by the \bottomrule.

How can I configure \topfigrule to be active only for figures?

Assume that there is always only one float at the top of the page, either a table or a figure.

MWE: first page with table, second page with figure. The first page should not get a topfigrule.

\documentclass[captions=tableheading]{scrbook}
\usepackage{booktabs}
\usepackage{blindtext}

\newcommand{\topfigrule}{\vspace{0.5cm}\hrule}
\setlength{\textfloatsep}{0.5cm}

\begin{document}

\blindtext

\begin{table}
  \caption{Foo}
  \centering
  \begin{tabular}{@{}ccccc@{}}
    \toprule
     1 & 2 & 3 & 4 & 5\\\midrule
     a & b & c & d & e\\
     \bottomrule
  \end{tabular}
\end{table}

\clearpage

\blindtext

\begin{figure}
  \centering
  \caption{Bar}
  \rule{2cm}{2cm}
\end{figure}

\end{document}
  • Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Werner Feb 27 '13 at 21:12
3

LaTeX doesn't normally keep track of float type at that point, but you can make it remember the last type it saw and then make the rule conditional on that:

enter image description here

\documentclass{article}

\makeatletter
\def\@comflelt#1{%
{\count@\count#1\divide\count@32 \xdef\lasttype{\the\count@}}%
\setbox\@tempboxa
      \vbox{\unvbox\@tempboxa\box #1\vskip\floatsep}}

\newcommand{\topfigrule}{\ifnum\lasttype=1\hrule\fi}

\makeatother

\begin{document}
aaa

\begin{table}[t]\caption{ccc} xxx\end{table}

bbb

\newpage

aaa

\begin{figure}[t]xxx \caption{kkk}\end{figure}

bbb

\end{document}
| improve this answer | |

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.