TransWikia.com

Xcolor for verbatim in Latex

TeX - LaTeX Asked on December 20, 2021

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.9linewidth}
        
        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.9linewidth}
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

One Answer

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}

Answered by js bibra on December 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP