2

I am writing an informative text and I need to use verbatim, below I have a code that is working in normal texts.

\colorbox{gray!10}{
    \begin{minipage}{0.9\linewidth}
        
        TEXT
        
\end{minipage}}

Now below the text inside the verbatim environment and I can't give the same background color as the other.

\colorbox{gray!10}{
    \begin{minipage}{0.9\linewidth}
\begin{verbatim}
        
        TEXT
        
\end{verbatim}
\end{minipage}}

How can I put all verbatim text in a frame like normal text? I'm using the xcolor package

1
  • tcolrobox + listing library does à very good job.
    – projetmbc
    Commented Jul 24, 2020 at 6:28

1 Answer 1

1

Does this work for you --from --

https://gist.github.com/parthi2929/2855a9c1792c7ff0ebe67205ee023999

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage{fancyvrb} % verbatim replacement that allows latex
\usepackage[breakable]{tcolorbox}

\definecolor{cellborder}{HTML}{CFCFCF}
\definecolor{cellbackground}{HTML}{F7F7F7}    

\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}

\newenvironment{InVerbatim}{\VerbatimEnvironment%
    \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,
        colback=cellbackground, colframe=cellborder]
        \begin{Verbatim}
        }{
        \end{Verbatim}
    \end{tcolorbox}
}   

\begin{document}    
    
    trrgdsgh 
    
    \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm, colback=cellbackground, colframe=cellborder]
        \begin{verbatim}
        tesdt
        \end{verbatim}
    \end{tcolorbox}
    
    \begin{InVerbatim}
        this is via environment setting
    \end{InVerbatim}
    
\end{document}
1
  • 3
    I would strongly recommend you remove the packages this example is not actually using, and pare it down into a MWE. In particular, copying \usepackage[latin1]{inputenc} into another document would be extremely harmful.
    – Davislor
    Commented Jul 24, 2020 at 2:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .