GeneralText in a framed Box with a customized Caption

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
amppinheiro
Posts: 4
Joined: Wed Jun 06, 2012 11:32 am

Text in a framed Box with a customized Caption

Post by amppinheiro »

Hi,

So I want to add a kind of a storyline into my document. I want these stories to be enclosed into a box. So I used the framed command, but there is a big problem, it seems that this package does not support captions.

I tried listings, but i cannot use text formatting commands like \textbf or \underline which I need.

An output example of what I wish to achieve is this (the position of the caption and box style is irrelevant:

------------------------------------------------------------------
| Story: Lorem ipsum dolor sit amet |
| Nullam suscipit nunc eu libero blandit porta.|
| Cum sociis natoque penatibus et magnis dis |
| parturient montes, nascetur ridiculus mus. |
------------------------------------------------------------------
Box 1 - Lorem ipsum
Is there a way to achive what I want? Also can I set a default caption type? (I think box does not exist, but even if it exists I would like to set my own).

I have already searched a lot for this answer, some of the topics I've read seems to suggest the solution could be achieved with {minipage} enviroment. But it does not seems to allow to set a caption. Hope you guys can help me! Thanks :)

Recommended reading 2024:

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

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

shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Text in a framed Box with a customized Caption

Post by shadgrind »

You can use TikZ and the newfloat package. There is already a \box command, so I called the new type 'story' but have it displayed as "Box":

Code: Select all

\documentclass{article}
\usepackage{newfloat}
\usepackage{caption}
\usepackage{tikz}
\newcommand{\framedbox}[2][0.96\textwidth]{
 \centering
 \tikzstyle{mybox} = [draw=black,line width=1.2pt,inner sep=8pt]
 \begin{tikzpicture}
  \node [mybox] (box){%
   \begin{minipage}{#1}{#2}\end{minipage}
  };
 \end{tikzpicture}
}

\DeclareFloatingEnvironment[listname=Box,name=Box]{story}
\captionsetup[story]{listformat=simple}

\begin{document}
Here's a framed box with a custom width:

\begin{story}[ht]
 \framedbox[0.5\textwidth]{\textbf{Story:}
 Lorem ipsum dolor sit amet
 Nullam suscipit nunc eu libero blandit porta.
 Cum sociis natoque penatibus et magnis dis
 parturient montes, nascetur ridiculus mus.}
 \caption[]{ Lorem ipsum}
 \label{box:box1}
\end{story}

Here's another one with the default width:

\begin{story}[ht]
 \framedbox{\textbf{Story:}
 Lorem ipsum dolor sit amet
 Nullam suscipit nunc eu libero blandit porta.
 Cum sociis natoque penatibus et magnis dis
 parturient montes, nascetur ridiculus mus.}
 \caption[]{ Lorem ipsum part deux}
 \label{box:box2}
\end{story}
\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Text in a framed Box with a customized Caption

Post by CrazyHorse »

Code: Select all

\documentclass{article}
\usepackage{floatrow}
\makeatletter
\DeclareNewFloatType{stories}{name=Story,placement=!htb,fileext=box}
\newsavebox\floatb@x
\newenvironment{story}[1][\textwidth]
  {\begin{stories} 
   \begin{lrbox}{\floatb@x}\minipage{#1}\textbf{Story:} }
  {\endminipage\end{lrbox}\fboxrule=2pt%
   \fbox{\usebox\floatb@x}\end{stories}}
\makeatother

\begin{document}
    Here's a framed box with a custom width:

\begin{story}
     Lorem ipsum dolor sit amet
     Nullam suscipit nunc eu libero blandit porta.
     Cum sociis natoque penatibus et magnis dis
     parturient montes, nascetur ridiculus mus.
\caption{ Lorem ipsum}\label{box:box1}
\end{story}

Here's another one with the default width:

\begin{story}[0.5\linewidth]
     Lorem ipsum dolor sit amet
     Nullam suscipit nunc eu libero blandit porta.
     Cum sociis natoque penatibus et magnis dis
     parturient montes, nascetur ridiculus mus.
\caption{ Lorem ipsum part deux}\label{box:box2}
\end{story}

\listof{stories}{List of stories}      
\end{document}
amppinheiro
Posts: 4
Joined: Wed Jun 06, 2012 11:32 am

Re: Text in a framed Box with a customized Caption

Post by amppinheiro »

Thank you very much for your response, shadgrind. I ended up using the other solution since it was the one I understood better. I am quite new to latex but I intend to search and learn the works of those packages you used to create that environment.

Also, thank you CrazyHorse for your answer, it worked like a charm. The possibility to create a list of story is also very useful!

Again, thank you both for your time.
Post Reply