Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\begin{boxedlaw}{6.4in}
\colorbox[HTML]{F8E0E0}{
\begin{minipage}[c]{380px}
\begin{center}
\begine{verbatim}

\# define       LM_ENCA     18          //Port0
\# define       LM_ENCB     17          //Port0
\# define       RM_ENCA     29          //Port0
\# define       RM_ENCB     28          //Port0
\# define       LMDir       10          //Port0
\# define       RMDir       11          //Port0

\# define       LeftTx      21          //Port1
\# define       RightTx     20          //Port1
\# define       LfrontTx    17          //Port1
\# define       RfrontTx    16          //Port1

\# define      LeftRx       13          //Port0
\# define      RightRx      12          //Port0
\# define      LfrontRx     21          //Port0
\# define      RfrontRx     22          //Port0

\# define       Buzzer      31          //Port1
\# define       ModeSel     2           //Port0

\# define       GyroOut     5           //Port0
\# define       GyroOut4X   4           //Port0

\end{verbatim}
\end{center}
\end{minipage}}
\end{boxedlaw}

When I use this code I keep getting an error:

"! Missing $ inserted."
"! Missing } inserted."

I have declared this new environment at the start:

\usepackage{xcolor}         % Extended colors
\usepackage{color}         % Color extended names

%DEFINE ENVIRONMENT BLOCK
% Riddle
\newenvironment{colbox}[3]{        % Riddle environment
  \begin{center}                   % Centering minipage
    \colorbox[HTML]{#1} {          % Set's the color of minipage
      \begin{minipage}[b]{380px}   % Starts minipage
   \textbf{#2}\\ \textit{#3}       % Set's title and starts italic for text
  \end{minipage}}                  % End minipage
}{\end{center}}                    % End Riddle environment

The above environment is something I have copied from a different post on this forum. However being a novice with Latex I dont know if I can use it as it is. Any help would be great.

share|improve this question
    
Welcome to TeX.sx! It would be create if you could add your code as a full minimal working example (MWE) which can be directly compiled by other people. –  Martin Scharrer Apr 18 '12 at 18:42
    
I am confused; you defined a colbox environment (last snippet) but you use a boxedlaw environment in the first snippet; where is this environment defined? Also, there's a missing \begin{verbatim} in the first snippet. –  Gonzalo Medina Apr 18 '12 at 18:42
    
Sorry @GonzaloMedina. I forgot the \begin{verbatim}. What I am interested in is to get the text between the verbatim environment in a colred box with an outline around it. –  Karan Thakkar Apr 18 '12 at 18:46
    
@KaranThakkar: You can't use verbatim inside a macro argument, here the \colorbox. Also, when you use verbatim you should turn the \# into #, right? –  Martin Scharrer Apr 18 '12 at 18:50
add comment

1 Answer 1

up vote 4 down vote accepted

You can't use the standard verbatim environment or the \verb command in the argument of another command. To write your verbatim material using a colored background, I would suggest you to use the listings package (refer to the package documentation to see all the features it provides):

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{mycolor}{HTML}{F8E0E0}

\begin{document}

\begin{lstlisting}[backgroundcolor=\color{mycolor},xrightmargin=2cm]
# define       LM_ENCA     18          //Port0
# define       LM_ENCB     17          //Port0
# define       RM_ENCA     29          //Port0
# define       RM_ENCB     28          //Port0
# define       LMDir       10          //Port0
# define       RMDir       11          //Port0

# define       LeftTx      21          //Port1
# define       RightTx     20          //Port1
# define       LfrontTx    17          //Port1
# define       RfrontTx    16          //Port1

# define       LeftRx      13          //Port0
# define       RightRx     12          //Port0
# define       LfrontRx    21          //Port0
# define       RfrontRx    22          //Port0

# define       Buzzer      31          //Port1
# define       ModeSel     2           //Port0

# define       GyroOut     5           //Port0
# define       GyroOut4X   4           //Port0
\end{lstlisting}

\end{document}

enter image description here

For non-verbatim material, you have the mdframed and adjustbox packages.

share|improve this answer
    
Yes, and for non-verbatim material there are the mdframed and adjustbox packages. –  Martin Scharrer Apr 18 '12 at 19:00
    
Thank you @GonzaloMedina. This is just what I wanted. –  Karan Thakkar Apr 18 '12 at 19:01
    
@MartinScharrer: yes; I added a little note to my answer. –  Gonzalo Medina Apr 18 '12 at 19:02
    
Okay. I guess I got the hint. –  Karan Thakkar Apr 18 '12 at 19:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.