2

I am using

\noindent\fbox{%
    \parbox{\textwidth}{%
        text
    }%
}

For a box around text like this: enter image description here

How can I add some caption and use this caption as reference in text?

Somethink like this:

enter image description here

2

You can use adjustbox for this. Use either the float or nofloat key. You need to define a new float type in either case, e.g. using newfloat package.

\documentclass{article}
\usepackage{lipsum}% for example text only
\usepackage{hyperref}% for hyperlinked references

\usepackage{adjustbox}
\usepackage{newfloat}

\DeclareFloatingEnvironment[
fileext=loc,
listname={List of cars},
name=Car,
placement=pbth,
within=section,
%chapterlistsgaps=off,
]{car}

\begin{document}
\section{Bla}
\lipsum

\begin{adjustbox}{minipage=\textwidth-2\fboxsep-2\fboxrule, fbox, captionbelow={ferrari}, label={car:ferrari}, nofloat=car}
Test
\end{adjustbox}

See my new car~\ref{car:ferrari}.

\lipsum

\end{document}

enter image description here

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.