Text FormattingFloat Package, captions within boxes

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Hoed
Posts: 28
Joined: Sat Jan 07, 2012 12:46 pm

Float Package, captions within boxes

Post by Hoed »

Hey,

I'm writing a little book. Within this book, I want to set examples, definitions etc. in boxes, defined similar to the one in the example below (which is an example not generated by me). Because I wanted the boxes to be floating objects, I defined a float-environment similar to those used for tables using the package float. However, the captions used for diagramms, tables... within those boxes are printed below the boxes. The float-packages description is not of any help here, as the defined caption-formats always put the caption outside the boxes.

Here's what I want to do: Define a box like in the code using mdframed, place a diagramm, a table... within this box and give a caption to that object. The caption should be place above the object within the box.

Any suggestions are welcome....


Code: Select all

\documentclass[paper=A4]{scrbook}

\usepackage{blindtext} %Blindtext Überprüfung von Satzspiegel/Lesbarkeit

\usepackage{scrhack}

\usepackage[ngerman]{babel} %Sprachpaket
\usepackage[T1]{fontenc} %Sonderzeichen, Umlaute
\usepackage[latin9]{inputenc} %Sonderzeichen, Umlaute



\usepackage[sort,square,colon]{natbib} %Bibliography

\usepackage{makeidx} %Index
\usepackage{imakeidx} %Index
\usepackage{fancybox}

\usepackage{framed}
\usepackage[tableposition=top,figureposition=top]{caption}
\DeclareCaptionFont{nicered}{\color{nicered}}
\captionsetup{labelfont={nicered,bf},textfont={nicered,bf}}
\usepackage{subcaption}

\usepackage{graphicx} %Einbinden von Abbildungen
\usepackage{tikz} %TIKZ
\usetikzlibrary{arrows,automata,calc,shapes,patterns,decorations,positioning,shadows,intersections,3d,decorations.pathreplacing} %TIKZ-Options
\usepackage{animate} 
\usepackage{tcolorbox}
%\usepackage{pstricks} %% erst einmal auskommentiert. Es gibt Probleme mit der "Opacity" bei TIKZ-Graphiken
\usepackage[framemethod=tikz]{mdframed}

\usepackage{float}


\definecolor{nicered}{rgb}{.647,.129,.149}
\definecolor{redtitleback}{cmyk}{0,0.1,0.1,0}


\newcounter{Beispiel}[section]
\newenvironment{Beispiel}[1][]{%
	\refstepcounter{Beispiel}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[line width=1pt,anchor=east,rectangle,draw=nicered,fill=redtitleback,general shadow={shadow scale=1, shadow xshift=0.8ex, shadow yshift=-0.8ex,
					opacity=1, fill=gray!50}]
				{\strut \color{nicered}{Beispiel}~\theBeispiel};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[line width=1pt,anchor=east,rectangle,draw=nicered,fill=redtitleback, general shadow={shadow scale=1, shadow xshift=0.8ex, shadow yshift=-0.8ex,
					opacity=1, fill=gray!50}]
				{\strut \color{nicered}{Beispiel}~\theBeispiel:~\color{nicered}{#1}};}}%
	}%
	\mdfsetup{roundcorner=10pt,innertopmargin=10pt,linecolor=nicered,%
		linewidth=1pt,topline=true,shadow=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
	\begin{mdframed}[]\relax%
	}{\end{mdframed}}


\floatstyle{plain}
\newfloat{float}{thp}{cit}
\floatname{float}{Float}



 \begin{document}
 	\begin{float}
 \begin{Beispiel}
   \centering
    \captionof{figure}{Main caption for subfigures \subref{fig:subfig1}, \subref{fig:subfig2} and \subref{fig:subfig3}}
    \begin{subfigure}[b]{0.45\textwidth}
        \subcaption[short for lof]{Caption for sub-figure 1}
        \rule{\linewidth}{3cm}
        \label{fig:subfig1}
    \end{subfigure}%
    \quad
    \begin{subfigure}[b]{0.45\textwidth}
        \subcaption[short for lof]{Caption for sub-figure 2}
        \rule{\linewidth}{3cm}
        \label{fig:subfig2}
    \end{subfigure}
 
    \begin{subfigure}[b]{0.45\textwidth}
        \subcaption[short for lof]{Caption for sub-figure 3}
        \rule{\linewidth}{3cm}
        \label{fig:subfig3}
    \end{subfigure}
\end{Beispiel}
\end{float}
\end{document}

Recommended reading 2024:

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

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

Hoed
Posts: 28
Joined: Sat Jan 07, 2012 12:46 pm

Float Package, captions within boxes

Post by Hoed »

Can be closed. I'm sorry for opening this topic.

Easy solution is using:

Code: Select all

\DeclareCaptionType[fileext=ext]{float}
instead of the float-package.

Thanks.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Re: Float Package, captions within boxes

Post by Stefan Kottwitz »

Hi Hoed,

thank you for telling us your solution!

No problem with the topic, feel free to open a new topic whenever you got a question. Also, your topic with the answer can help other people searching for it via google. So any topic which can be kind of solved is useful for the TeX world.

Stefan
LaTeX.org admin
Post Reply