1

Here is my code to create an info box:

\documentclass{article}

\usepackage{float}
\usepackage{blindtext}


\floatstyle{ruled} 
\newfloat{InfoBox}{h}{}


\begin{document}

\begin{InfoBox}
\vspace{0.5cm}
\textbf{Point 1} \blindtext

\medskip
\textbf{Point 2} \blindtext

\medskip
\textbf{Point 3} \blindtext
\vspace{0.5cm}
\caption{This a caption}
\end{InfoBox}

\end{document}

How could I add a background color between the two lines that contain the main text? Thanks in advance!!

  • You might be interested in tcolorbox. – leandriis Oct 2 at 6:42
  • @José what do you consider as the main text? – Alexandre Quenon Oct 2 at 9:24
  • Every text line but the caption – José Oct 2 at 12:13
2

Here below is a solution based on this : How to highlight an entire paragraph?

Mechanism

I created a new float style by using the same way as the float package does for the 'ruled' style. Then I used the framed package and its snugshade environment to create the color box.

It looks like this:

enter image description here

Code

\documentclass{article}

% Mandatory package
\usepackage{float}
\usepackage{xcolor}
\usepackage{framed}

% To change the color
\colorlet{shadecolor}{yellow!20}
%\colorlet{shadecolor}{blue!20}

% For test only
\usepackage{blindtext}

\renewcommand*{\OuterFrameSep}{0pt}

% Creation of a new floatstyle 'toto'
\makeatletter
    \newcommand\floatc@toto[2]{{\@fs@cfont #1} #2\par}
    \newcommand\fs@toto{%
        \def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@toto
        \def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
        \def\@fs@mid{%
            \kern2pt\hrule\kern2pt
            \begin{snugshade}
        }%
        \def\@fs@post{%
            \end{snugshade}
            \kern2pt\hrule\relax
        }%
        \let\@fs@iftopcapt\iftrue}
\makeatother

\floatstyle{toto} 
\newfloat{InfoBox}{h}{}


\begin{document}

    \begin{InfoBox}
        \vspace{0.5cm}
        \textbf{Point 1} \blindtext

        \medskip
        \textbf{Point 2} \blindtext

        \medskip
        \textbf{Point 3} \blindtext
        \vspace{0.5cm}
        \caption{This a caption}
    \end{InfoBox}

\end{document}
  • Thanks so much! – José Oct 3 at 7:54

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.