GeneralReport Layout

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Report Layout

Post by cbustaam »

Hi gmedina,
I'm having some problems when I use the subfig package with the options of float package. The MWE is:

Code: Select all

\documentclass{report}
\usepackage[svgnames]{xcolor}
\usepackage{float}
\usepackage{subfig}

\makeatletter
\renewcommand\floatc@ruled[2]%
  {\setbox\@tempboxa\hbox{#2}%
   \ifdim\wd\@tempboxa>\hsize #2\par%
   \else\hbox to\hsize{\hfil\box\@tempboxa\hfil}\fi}
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled%
  \def\@fs@pre{\vspace*{0pt}\hrulefill\lower.8ex
    \hbox{\colorbox{MidnightBlue}{%
      \textcolor{white}{\scriptsize GR\'AFICO\ \thefigure}}}%
    \hrulefill\vspace{10pt}}%
  \def\@fs@post{\vspace{3pt}\kern2pt\hrule\relax}%
  \def\@fs@mid{\addvspace{10pt}}
  \let\@fs@iftopcapt\iftrue}
\makeatother

\floatstyle{ruled}
\restylefloat{figure}

\begin{document}

\begin{figure}[!ht]
   \centering
  \rule{4cm}{2cm}
   \caption{A test figure}
   \label{fig:test}
\end{figure}

aaa

\begin{figure}[!ht]
\caption{Test Subfigures}
\centering
\subfloat[aaa]{
\centering
\rule{4cm}{2cm} 
}
\subfloat[bbb]{
\centering
\rule{4cm}{2cm}
}
\end{figure}

\end{document}
The float captions doesn't appear in the right way. Any suggestion?

Bests
"Show me your .emacs and I'll tell you who you are." -- modified proverb

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Report Layout

Post by gmedina »

Hi,

yes... those two packages don't cooperate very well. You can use the subcaption package (a useful companion of the caption package) instead:

Code: Select all

\documentclass{report}
\usepackage[svgnames]{xcolor}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\DeclareCaptionStyle{ruled}%
  {labelformat=empty,justification=centering,strut=off}

\makeatletter
\renewcommand\floatc@ruled[2]%
  {\setbox\@tempboxa\hbox{#2}%
   \ifdim\wd\@tempboxa>\hsize #2\par%
   \else\hbox to\hsize{\hfil\box\@tempboxa\hfil}\fi}
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled%
  \def\@fs@pre{\vspace*{0pt}\hrulefill\lower.8ex
\hbox{\colorbox{MidnightBlue}{%
  \textcolor{white}{\scriptsize GR\'AFICO\ \thefigure}}}%
\hrulefill\vspace{10pt}}%
  \def\@fs@post{\vspace{3pt}\kern2pt\hrule\relax}%
  \def\@fs@mid{\addvspace{10pt}}
  \let\@fs@iftopcapt\iftrue}
\makeatother

\floatstyle{ruled}
\restylefloat{figure}

\begin{document}

\begin{figure}[!ht]
   \centering
  \rule{4cm}{2cm}
   \caption{A test figure}
   \label{fig:test1}
\end{figure}

aaa

\begin{figure}[!ht]
\caption{Test Subfigures}
\label{fig:test2}
\centering
\begin{minipage}{4.5cm}
  \centering
  \rule{4cm}{2cm}
  \subcaption{a test subfigure}
  \label{sub:testsubfig1}
\end{minipage}
\begin{minipage}{4.5cm}
  \centering
  \rule{4cm}{2cm}
  \subcaption{a test subfigure}
  \label{sub:testsubfig2}
\end{minipage}
\end{figure}

\end{document}
Here you can find the documentation for subcaption.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply